HTML Javascript 幻灯片优化
HTML Javascript Slideshow Optimization
我不得不编写自己的几行代码,以便在我的网站启动页面上显示幻灯片。我无法使用任何插件,因为我在HTML5和css3上设计了网站,并且图像与浏览器同步以调整大小。现在,来到实际问题,最后一张图像花费了两倍的时间列表中的每个图像。下面是粘贴的 HTML 和 JavaScript。
.HTML
<div id="backgrounds">
<div class="bgs" style="z-index:1000;">
<!--<p style="z-index:999; margin:0; margin-top:300px; color:red; position:absolute;">Let the Feeling Wrap Around</p>-->
<img src="images/main_nop.jpg" alt="" class="background" />
</div>
<div class="bgs" style="z-index:999; display: none">
<!--<p style="z-index:999; margin:0; margin-top:300px; color:red; position:absolute;">Let the Feeling Wrap Around</p>-->
<img src="images/main_jkl.jpg" alt="" class="background" />
</div>
<div class="bgs" style="z-index:998; display: none">
<!--<p style="z-index:999; margin:0; margin-top:300px; color:red; position:absolute;">Let the Feeling Wrap Around</p>-->
<img src="images/main_ghi.jpg" alt="" class="background" />
</div>
<div class="bgs" style="z-index:997; display: none">
<!--<p style="z-index:999; margin:0; margin-top:300px; color:red; position:absolute;">Let the Feeling Wrap Around</p>-->
<img src="images/main_def.jpg" alt="" class="background" />
</div>
<div class="bgs" style="z-index:996; display: none">
<!--<p style="z-index:999; margin:0; margin-top:300px; color:red; position:absolute;">Let the Feeling Wrap Around</p>-->
<img src="images/main_abc.jpg" alt="" class="background" />
</div>
</div>
JAVASCRIPT
var count = 0;
var repeatCount = 0;
var backgrounds = $('.bgs').length;
function startSlideShow() {
myRecFunc = setInterval(function () {
if (count == backgrounds) {
$('.bgs').eq(0).stop(true, true).hide(1000, 'easeOutExpo');
$('.bgs').eq(backgrounds - 1).show(1000, 'easeOutExpo');
}
if (count < backgrounds) {
$('.bgs').eq(count).stop(true, true).show(1000, 'easeOutExpo');
$('.bgs').eq(count - 1).stop(true, true).hide(1000, 'easeOutExpo');
count++;
}
else {
count = 0;
repeatCount++;
}
}, 1000);
}
startSlideShow();
上面代码中的第一个 if() 是我添加的用于处理我在上面陈述的情况的那个,提前感谢您的帮助。
你有一个条件,你在整个时间间隔内什么都不做,这是你的"其他"情况。 尝试将该检查移到内部,以便立即发生。
var count = 0;
var repeatCount = 0;
var backgrounds = $('.bgs').length;
function startSlideShow() {
myRecFunc = setInterval(function () {
$('.bgs').eq(count).stop(true, true).show(1000, 'easeOutExpo');
$('.bgs').eq(count - 1).stop(true, true).hide(1000, 'easeOutExpo');
count++;
if (count === backgrounds) {
count = 0;
repeatCount++;
}
}, 1000);
}
startSlideShow();
相关文章:
- 幻灯片滚动javascript不起作用
- 让文本输入幻灯片显示输入时的新文本输入?然后向后滑动
- 创建具有可变长度幻灯片显示的幻灯片
- 以可优化的方式使用requirejs加载模板
- 通过幻灯片更改事件停止使用jquery的音频
- 使用优化器在慢速连接上加载main.js时需要js超时
- JavaScript数组优化以提高性能
- 不能在同一页上进行多个jquery幻灯片切换
- React+Redux性能优化与组件ShouldUpdate
- 我可以使此幻灯片图像自动播放吗?
- JS幻灯片与CSS背景颜色变化
- 带有计数器、缩略图、进度条和淡入淡出效果的简单jQuery幻灯片
- jQuery图像幻灯片,在停止后淡出到第一张图像
- 删除“;上一个“;以及“;下一个“;基于当前幻灯片
- JQuery幻灯片,可点击编号位置
- JavaScript尾部调用中的函数是否经过优化
- javascript中的快捷方式融合优化
- Jquery幻灯片以一行左侧的图像开始,但我希望它从右端开始
- HTML Javascript 幻灯片优化
- 优化幻灯片与数百个图像