我怎样才能制作一个类似窗口滚动控制系统的好友推送?
当您激活实时更新时,新条目会动态添加 div。在此阶段,滚动条会自动移动。此操作在可见区域提供您不会错过的内容。
如果你想看这个动作,你也可以观看这个截屏视频; http://www.viddler.com/explore/itod/videos/45/ < /a>
我的方法;
// Firstly, i am storing the first entry's(in view) positions in window object;
jQuery(window).scroll(function() {
var q = 0;
jQuery(".entry").each(function (i) {
if (jQuery(this).offset().top > jQuery(window).scrollTop()) {
if (q == 0) {
window.show_id = jQuery(this).attr("id");
window.pos_y = jQuery(this).offset().top - jQuery(window).scrollTop();
q = 1;
}
}
});
});
// After coming to the new entry, i call this function;
function scroll_control() {
var scroll_top = jQuery(window).scrollTop();
if (scroll_top != 0) {
if (jQuery('#'+window.show_id).length != 0) {
var scr = jQuery('#'+window.show_id).offset().top - window.pos_y;
window.scrollTo(0, scr);
}
}
}
// but this is due to flashing. I guess not fast enough
When you active real-time updates, new entries dynamically adding a div. At this stage scroll is automatically moving. This action provides the content you do not miss on visible area.
If you want to see this action, you can also watch this screencast; http://www.viddler.com/explore/itod/videos/45/
My method;
// Firstly, i am storing the first entry's(in view) positions in window object;
jQuery(window).scroll(function() {
var q = 0;
jQuery(".entry").each(function (i) {
if (jQuery(this).offset().top > jQuery(window).scrollTop()) {
if (q == 0) {
window.show_id = jQuery(this).attr("id");
window.pos_y = jQuery(this).offset().top - jQuery(window).scrollTop();
q = 1;
}
}
});
});
// After coming to the new entry, i call this function;
function scroll_control() {
var scroll_top = jQuery(window).scrollTop();
if (scroll_top != 0) {
if (jQuery('#'+window.show_id).length != 0) {
var scr = jQuery('#'+window.show_id).offset().top - window.pos_y;
window.scrollTo(0, scr);
}
}
}
// but this is due to flashing. I guess not fast enough
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您想平滑地滚动到顶部而不是跳到解决“闪烁”问题。我会做这样的事情:
I assume you want to scroll smoothly to the top instead of jumping to solve 'flashing'. I would do something like this: