javascript - 从页面底部滑入一个div?

标签 javascript html css

我正在尝试实现与本页中的效果类似的效果:

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 滚动动画

http://jsfiddle.net/ySeWk/

关于javascript - 从页面底部滑入一个div?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17833828/

相关文章:

html - <base href =""> 破坏布局

html - 重复 css 图像作为内容

html - 使 div 中的某些单词具有不同的样式会使段落中断真的很奇怪

javascript - 在 &lt;script&gt; 标签中声明一个 function() 是必要的吗?

css - bootstrap css 如何针对所有类 .table 独立于父/子?

javascript - 如何组织多个 View 使用的 Backbone 模型?

javascript - 使用 React JS 在所有段落中添加 SPAN 元素

javascript - 通过 Google Website Optimizer 的多变量测试,我可以在一个 div 上改变多个 css 类吗?

JavaScript-不显示文本 Accordion 中的标题

html - 将 io.BytesIO 转换为 io.StringIO 来解析 HTML 页面