如何防止在前面滚动?

How to prevent scrolling on prepend?(如何防止在前面滚动?)
本文介绍了如何防止在前面滚动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我将内容添加到正文的顶部.有时,此内容可能有 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.

这篇关于如何防止在前面滚动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Google apps script get range of bytes from binary file(谷歌应用程序脚本从二进制文件中获取字节范围)
Sending Multiple attachments with Google Script from Google Drive(使用 Google 脚本从 Google Drive 发送多个附件)
Distributing Google Apps Scripts for Sheets in your company network(在您的公司网络中分发适用于表格的 Google Apps 脚本)
Upload file to my google drive from anyone using javascript(使用 javascript 将文件从任何人上传到我的谷歌驱动器)
quot;Shared Drivequot; support in Google Apps Script(“共享驱动器Google Apps 脚本中的支持)
Angular 2+ HTTP POST and GDrive API. Resumable file upload with name(Angular 2+ HTTP POST 和 GDrive API.带名称的可恢复文件上传)