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");
}
}
精彩评论