简体   繁体   中英

External JS file works perfectly well in Firefox but not in IE

Here's the code right away in my separate JS file:

$(function () {
    $(window).scroll(function () {

        if ($('.span4').css("left") == "0px") {
            $('.span4').css("left", "auto");
        } else if ($('.span4').css("left") < "0px") {
            $('.span4').css('left', -$(window).scrollLeft() - 20);
        }
    })
});
$(function () {
    $(window).resize(function () {

        if ($(window).width() >= "1130") {
        $('.span4').css("left", "auto");
        }
    })
});

This perfectly works well in Firefox but in IE (facepalm).... But if i place this code inline in the html it works well in both IE and Firefox... why you IE :(

Could be any number of things. Maybe it's not being invoked in IE. Try the following

$(function () {
$(window).scroll(function () {

    if ($('.span4').css("left") == "0px") {
        $('.span4').css("left", "auto");
    } else if ($('.span4').css("left") < "0px") {
        $('.span4').css('left', -$(window).scrollLeft() - 20);
    }
})
})();
$(function () {
$(window).resize(function () {

    if ($(window).width() >= "1130") {
    $('.span4').css("left", "auto");
    }
})
})();

All I've done it add "()" to the end of each function so that it invoked immediately. Worth a try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM