如何在没有动画的情况下滚动到 [英] how to scrollto without animation

查看:52
本文介绍了如何在没有动画的情况下滚动到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我使用了 lions-mark 中出色的插件,该插件可以滚动到任意位置微风.我主要用它来在页面刷新时将用户保持在其当前滚动位置(不要问,我的网站是旧游戏网站,在某些情况下会自动刷新)

因此,我将当前滚动位置存储到 window.onBeforeUnload 上的localstorage中,并使用该值在页面加载后滚动到先前的位置.

$('content-grid').scrollTo(offsetBeforeReload);

这有效,但是我想在没有动画滚动的情况下跳到"该位置.我不想使用锚,因为我已经有了可以正常运行的scrollTo代码,所以我要做的就是摆脱scrollTo动画并使它看起来好像页面已锚定"到该位置.

非常感谢任何建议/解决方案!

解决方案

只需使用 window.scrollTo .这将直接跳到没有动画的位置.

  var xPosition = 0;var yPosition = 1000;window.scrollTo(xPosition,yPosition); 

So I use the excellent plugin from lions-mark that allows scrolling to any position a breeze. I use this mainly to keep the user at his current scroll location when the page refreshes (don't ask, mine is a legacy gaming site with auto-refresh in some instances)

So I store current scroll position into localstorage on window.onBeforeUnload and use that value to scroll to previous location after pageload.

$('content-grid').scrollTo(offsetBeforeReload);

This works, however I want to "jump" to that position without the animated scroll. I do not want to use anchors, since I already have this scrollTo code that works just fine, all I want to do is get rid of the scrollTo animation and made it look as if the page is 'anchored' to that location.

Any suggestions/solutions are very much appreciated!

解决方案

Just use window.scrollTo. This will jump directly to the position with no animations.

var xPosition = 0;
var yPosition = 1000;
window.scrollTo(xPosition, yPosition);

这篇关于如何在没有动画的情况下滚动到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆