我正在尝试实现与本页中的效果类似的效果:
Slide Up/Down DIV from bottom center of the page using jquery
但我需要它在页面加载时延迟 5-6 秒!
这只能用 CSS 或纯 javascript 来完成吗?如果是,怎么办?
谢谢
最佳答案
JQUERY:
将它与 window.onload = function ...
一起使用
setTimeout(function() {
var top = $('#yourID').position().top;
document.getElementById('youridhere').scrollIntoView();
}, 5000); // your timeout in ms
JavaScript
老问题,但是如果有人通过谷歌找到这个(就像我一样)并且不想使用 anchor 或 jquery,那么有一个内置的 javascript 函数可以“跳转”到一个元素。
document.getElementById('youridhere').scrollIntoView();
更好的是,根据 quirksmode 上的兼容性表,这是 supported by all major browsers !
或 您可以使用 anchor 来“聚焦”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";
还有其他 看看这个 fiddle :) 有一个 javascript 仅滚动动画
关于javascript - 从页面底部滑入一个div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17833828/