【发布时间】:2013-05-24 02:42:17
【问题描述】:
有问题的 Div 是右侧边栏上的灰色框 this link。
很好地滚动,但它永远不会停止。它应该在到达“公告”div 之前停止。
我知道有一个非常相似的问题和类似的答案here,但它没有被检查,我无法让它工作。
我充其量是 jQuery 的新手,所以我非常感谢 2 岁的风格答案。
触发div滚动的代码是:
$(function () {
var msie6 = $.browser == 'msie' && $.browser.version < 7;
if (!msie6) {
var top = $('#comment').offset().top - parseFloat($('#comment').css('margin-top').replace(/auto/, 0));
$(window).scroll(function (event) {
// what the y position of the scroll is
var y = $(this).scrollTop();
// whether that's below the form
if (y >= top) {
// if so, ad the fixed class
$('#comment').addClass('fixed');
} else {
// otherwise remove it
$('#comment').removeClass('fixed');
}
var newWidth = $('#comment').parent().width();
$('#comment').width(newWidth);
});
}
});
【问题讨论】:
-
我没有看到“公告”div。它在哪里?
-
@asifrc 我认为它是一个 ID,就在 cmets 下方
-
感谢@ArunPJohny,我只是在浏览 html,但通过 jQuery/console 找到了它。
-
jQuery.browser自 1.3 以来已被弃用,并已在 jquery 1.9 中删除。你真的应该使用特征检测。