JS和HTML幻灯片跳转不使用绝对位置
JS and HTML slideshow jumps is not using position absolute
我正在尝试创建一个简单的 Div 幻灯片,这是我到目前为止所拥有的:http://jsfiddle.net/ZZLHF/
.HTML:
<div class="slideShow">
<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled including versions of Lorem Ipsum.
</div>
<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</span>
</div>
</div>
.JS:
//Side Show
$(function () {
$('.slideShow div:gt(0)').hide();
setInterval(function () {
$('.slideShow > :first-child').fadeOut().next('div').fadeIn().end().appendTo('.slideShow');
}, 1200);
});
正如你在JSfiddle中看到的 - 它会滑动,但它会跳跃!那是因为我有两个div,每个div都有不同数量的内容,所以没有指定高度,也因为我没有添加相对于.slideshow的位置和绝对的位置到其中的div。为什么?因为如果我这样做,我将不得不给它一个固定的高度。
如何阻止它跳跃并自动给它高度?
使用如下函数回调:
//Side Show
$(function () {
$('.slideShow div:gt(0)').hide();
setInterval(function () {
// 400 is default value
$('.slideShow > :first-child').fadeOut(400, function(){
$(this).next('div').fadeIn().end().appendTo('.slideShow');
})
}, 1200);
});
传递给 .fadeOut
的函数意味着当淡出完成时,执行函数中指定的操作。
演示
相关文章:
- 加载页面时更改html页面的位置
- HTML文档中脚本标记的位置-<头部>&<身体>有不同的行为
- 将Rails后端添加到JS/HTML/CSS应用程序时,正确的文件位置是什么
- JavaScript OnChange Listener在HTML标记中的位置
- 获取 HTML 5 音频控制文件位置并在不使用 id 选择器的情况下更新 src
- 一个html/javascript'小工具'知道用户何时单击了小部件外的任意位置
- 内容可编辑分区-根据内部HTML位置的光标位置
- 如何在提交html表单后保持相同的位置
- 如何使用位置获取滚动功能获取 HTML 中的元素标签
- 如何在 html Web 应用中检测滑动原点位置
- 如何使某个框等于图像HTML的位置
- HTML 按钮以在页面上的其他位置提交表单
- 为什么我在 webpack 中需要 html 文件时会得到一个位置字符串
- 如何在 Google App Engine 上存储 HTML 5 地理位置数据
- 如何获取相对于 HTML 页面的标记位置
- HTML重定向到错误的位置
- JSON获取地理位置在HTML中未返回值
- HTML-从javascript中的URL位置读取.txt文件
- 如何让滑块在ipad上点击到特定位置.HTML Javascript
- 谷歌浏览器不会问我的位置- html/ js