开发者

Use jquery show() and animate() together?

开发者 https://www.devze.com 2023-02-21 16:12 出处:网络
I have an issue getting jquery animate to fire after calling show or fadeIn on a hidden absolutely positioned div (display = none).The fadeIn/Show works fine, but the animate does nothing - and the lo

I have an issue getting jquery animate to fire after calling show or fadeIn on a hidden absolutely positioned div (display = none). The fadeIn/Show works fine, but the animate does nothing - and the logic function definitely evaluates to true after testing. I'm using IE9. Am I missing something?? Thanks.

function checkscroll(x) {

    $("#" + x).fadeIn(100);
    var t = $(window).height();
    var m = $("#" + x).offset();
    var p = m.top;
    var x = $("#" + x).height();

    if ((p + x) > t) {
        $("#" + x).anim开发者_如何学JAVAate({ marginBottom: "20px"}, "fast");

    }
}


After writing var x = $("#" + x).height();, x becomes a number, not an element ID.
Therefore, $("#" + x) doesn't match anything.

You should use longer, more descriptive variable names.


You're recreating the x variable, try using another variable instead.

Try this:

function checkscroll(id) {
    $("#" + id).fadeIn(100);
    var t = $(window).height();
    var m = $("#" + id).offset();
    var p = m.top;
    var x = $("#" + id).height();

    if ((p + x) > t) {
        $("#" + id).animate({ marginBottom: "20px"}, "fast");

    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消