在隐藏绝对定位的div(display = none)上调用show或fadeIn之后,我遇到了触发jquery动画的问题。 fadeIn / Show工作正常,但是animate没有任何作用 - 逻辑函数在测试后肯定会评估为true。我正在使用IE9。我错过了什么?感谢。
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).animate({ marginBottom: "20px"}, "fast");
}
}
答案 0 :(得分:2)
写var x = $("#" + x).height();
后,x
成为数字,而不是元素ID
因此,$("#" + x)
与任何内容都不匹配。
您应该使用更长,更具描述性的变量名称。
答案 1 :(得分:0)
您正在重新创建x变量,请尝试使用其他变量。
试试这个:
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");
}
}