如何使JQuery 1.8.3与其他jquery库兼容

时间:2013-07-29 23:16:59

标签: jquery conflict

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

$(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(函数($)所以它不会与其他jquery库中的其他$(document).ready冲突。如何写它以便$(window).load& resize不会是冲突?限制是版本1.8.3。谢谢。

1 个答案:

答案 0 :(得分: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
        });


}