0

我有这个代码来调整图像的位置

$(window).load(function() {
    center();

});


$(window).resize(function() {
        center();

});

function center() {
        var pos =  $('#banner img').width() - $(window).width();
        $('#banner img').css({
            left : pos / 2 * -1
        });
}

我知道使用 jQuery(function($) 所以它不会与其他 jquery 库中的其他 $(document).ready 发生冲突。如何编写它以便 $(window).load & resize 不会发生冲突?并且限制也是版本 1.8.3。谢谢。

4

1 回答 1

0

找到它...绑定事件似乎太有效了。

jQuery(window).on("load resize",function(e){
            center();
});

function center() {
        var pos =  jQuery('#banner img').width() - jQuery(window).width();
        jQuery('#banner img').css({
            left : pos / 2 * -1
        });


}
于 2013-07-30T00:13:56.067 回答