我将内容添加到正文的顶部.有时,此内容可能有 400-500 像素高,当添加此类内容时,在阅读页面时将内容向下推会非常烦人.
I'm prepending content to the top of the body. Sometimes this content can be 400-500px tall, and when something like this gets added, pushing the content down when you are reading the page it can be really annoying.
我希望自动添加项目,而不是单击此处查看新项目.
I want the items to be automatically prepended, not something like click here to see new items.
有没有办法在不移动页面的情况下将此内容添加到正文顶部?那么当用户滚动到顶部时它就已经在那里了?
Is there any way to prepend this content to the top of the body without moving the page? Then when a user scrolls to the top it is just there already?
我过去通过预先添加元素,然后计算它们的总外高,并将滚动顶部设置为该值来完成此操作.像这样的:
I've done it in the past by prepending the elements, then calculating their total outerheight, and setting the scrolltop to that value. Something like this:
var $current_top_element = $('body').children().first();
$('body').prepend(other_elements);
var previous_height = 0;
$current_top_element.prevAll().each(function() {
previous_height += $(this).outerHeight();
});
$('body').scrollTop(previous_height);
希望这会为您指明正确的方向.
Hope this points you in the right direction.
这篇关于如何防止在前面滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
用于创建头像的 jQuery/JavaScript 库?jQuery/JavaScript Library for avatar creation?(用于创建头像的 jQuery/JavaScript 库?)
如何做以下掩码输入问题?How to do following mask input problem?(如何做以下掩码输入问题?)
使用 DropKick Javascript 设置值/标签的问题Issues Setting Value/Label Using DropKick Javascript(使用 DropKick Javascript 设置值/标签的问题)
如何对 jquery 插件中的私有方法进行单元测试?how to unit-test private methods in jquery plugins?(如何对 jquery 插件中的私有方法进行单元测试?)
stellar.js - 为垂直滚动网站配置偏移量/对齐元素stellar.js - configuring offsets / aligning elements for a vertical scrolling website?(stellar.js - 为垂直滚动网站配置偏移量/对齐元素?)
jQuery 屏蔽输入插件.当文本框获得焦点时选择所有jQuery masked input plugin. select all content when textbox receives focus(jQuery 屏蔽输入插件.当文本框获得焦点时选择所有内容)