JavaScript将长页面滚动到DIV [英] JavaScript to scroll long page to DIV
问题描述
我在一个长的HTML页面上有一个链接。当我点击它时,我希望在页面的另一部分显示 div
,方法是滚动到视图中。
有点像 EnsureVisible
在其他语言中。
我已签出 scrollTop
和 scrollTo
,但它们看起来像是红鲱鱼。
任何人都可以帮忙吗?
老问题,但是如果有人通过谷歌发现了这个问题(如我所做的),谁不想使用锚或jQuery ;有一个内置的javascript函数来'跳转'到一个元素;
document.getElementById('youridhere')。scrollIntoView();
甚至更好;根据quirksmode上的强大兼容性表,这是受所有主流浏览器支持 !
I have a link on a long HTML page. When I click it, I wish a div
on another part of the page to be visible in the window by scrolling into view.
A bit like EnsureVisible
in other languages.
I've checked out scrollTop
and scrollTo
but they seem like red herrings.
Can anyone help?
old question, but if anyone finds this through google (as I did) and who does not want to use anchors or jquery; there's a builtin javascriptfunction to 'jump' to an element;
document.getElementById('youridhere').scrollIntoView();
and what's even better; according to the great compatibility-tables on quirksmode, this is supported by all major browsers!
这篇关于JavaScript将长页面滚动到DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!