我必须在滚动时保持元素在视图中。我已经完成了它并且它在所有浏览器中都运行良好,但不明智的分辨率。
$(function() {
var offset = $(".sysIcons").offset();
var topPadding = 15;
$(window).scroll(function() {
if ($(window).scrollTop() > offset.top) {
$(".sysIcons").stop().animate({
marginTop: $(window).scrollTop() - offset.top + topPadding
});
} else {
$(".sysIcons").stop().animate({
marginTop: 0
});
};
});
});
它在1024 x 768,1280 x 735,
中正常工作但不是在1360X768中, - 问题是在滚动到窗口结束时,它不会停止。滚动时连续动画。
请帮帮我
答案 0 :(得分:4)
在滚动时你不需要jQuery来获取视图中的元素,你可以使用CSS position
属性使它一直出现,包括滚动:
#elementID {
position:fixed;
/* more styles */
}
position:fixed
在IE6中不起作用,但是现在谁关心它:)
答案 1 :(得分:2)
这可能就是你想要的。
http://imakewebthings.com/waypoints/shortcuts/sticky-elements/ 主站点:http://imakewebthings.github.com/jquery-waypoints/ Github:https://github.com/imakewebthings/waypoints
答案 2 :(得分:0)
如果您不关心IE6,可以使用position: fixed
。