发布于 2013-07-24 12:32:59
JQUERY:
与window.onload = function ...一起使用
setTimeout(function() {
var top = $('#yourID').position().top;
document.getElementById('youridhere').scrollIntoView();
}, 5000); // your timeout in msJAVASCRIPT
这是个老生常谈的问题,但是如果有人像我一样通过google发现了这个问题,并且不想使用锚或jquery,那么就会有一个内置的javascript函数来“跳转”到一个元素。
document.getElementById('youridhere').scrollIntoView();而更好的是,根据伟大的兼容性-表的怪癖,这是所有主要浏览器都支持!
或您可以使用锚来“聚焦”div。即:
<div id="myDiv"></div>然后使用以下javascript:
// the next line is required to work around a bug in WebKit (Chrome / Safari)
location.href = "#";
location.href = "#myDiv";和看这个小提琴:)有一个只有滚动动画的javascript
http://jsfiddle.net/ySeWk/
https://stackoverflow.com/questions/17833828
复制相似问题