如何向幻灯片添加下一个和上一个控件
How to add next and prev controls to a slideshow
总的来说,我对编码还是比较陌生的。我需要创建一个滑块与控件,但我有问题编写下一个和上一个按钮的脚本。我一点也不懂。
$(function () {
$('#slideshow .show').hide(); // hide all slides
$('#slideshow .show:first-child').show(); // show first slide
setInterval(function () {
$('#slideshow .show:first-child').fadeOut(0)
.next('.show').fadeIn(1500)
.end().appendTo('#slideshow');
},
8500); // slide duration
$(".control_next").click(
//Not sure what to write here for the slider to fade to next slider
);
$(".control_prev").click(
//Not sure what to write here for the slider to fade to previous slider
);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slideshow">
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum</p>
</div>
<div class="textbg"></div>
<figure class="fixedratio"></figure>
</div>
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum</p>
</div>
<div class="textbg2"></div>
<figure class="fixedratio2"></figure>
</div>
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum</p>
</div>
<div class="textbg3"></div>
<figure class="fixedratio3"></figure>
</div>
</div>
<a href="#" class="control_next">></a>
<a href="#" class="control_prev"><</a>
感谢所有的帮助,谢谢!
我已经为next和previous按钮编写了代码,请检查。下一个按钮的代码非常简单。但是显示前一个元素的代码有点棘手。
var slideUpdating = false;
$(function () {
$('#slideshow .show').hide(); // hide all slides
$('#slideshow .show:first-child').show(); // show first slide
setInterval(
function ()
{
if (slideUpdating) {
return;
}
$('#slideshow .show:first-child')
.fadeOut(0)
.next('.show').fadeIn(1500)
.end().appendTo('#slideshow');
},
8500
); // slide duration
$(".control_next").click(
function () {
if(slideUpdating)
return;
slideUpdating = true;
$('#slideshow .show:first-child')
.fadeOut(0)
.next('.show').fadeIn(1500, function () {
slideUpdating = false;
})
.end().appendTo('#slideshow');
});
$(".control_prev").click(
function () {
if(slideUpdating)
return;
slideUpdating = true;
$('#slideshow .show:first-child')
.fadeOut(0)
.siblings(':last').fadeIn(1500, function () {
$("#slideshow .show:visible").prependTo("#slideshow");
slideUpdating = false;
});
}
);
});
.active {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slideshow">
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum1</p>
</div>
<div class="textbg"></div>
<figure class="fixedratio"></figure>
</div>
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum2</p>
</div>
<div class="textbg2"></div>
<figure class="fixedratio2"></figure>
</div>
<div class="show">
<div class="slidertext">
<span style="color:#007E5C; font-weight:800;">hello</span>
<p>Lorem Ipsum3</p>
</div>
<div class="textbg3"></div>
<figure class="fixedratio3"></figure>
</div>
</div>
<a href="#" class="control_next">></a>
<a href="#" class="control_prev"><</a>
相关文章:
- 后焦点更改为IE 11中的地址栏,而不是转移到表单中的下一个控件
- 用键盘分页jQuery下一个和上一个控件.触发器('点击')不'不起作用
- 使用Jquery从MasterPage访问子页上的控件
- 引导程序转盘隐藏第一个和最后一个控件
- 清除/重置网格视图中的文件上载控件
- 从文件上载控件中删除特定文件
- 如何从另一个控件调用 onclick 事件
- YouAtNotes HTML5 上传控件 - 使用外部数据库源代码
- 通过锚标记将另一个控件的客户端 ID 发送到 JavaScript
- 从客户端上传文件,不使用文件上传控件
- 所有文件都不是使用 jquery 从文件上传控件获取的
- 计算空文件上传控件
- 使用 jQuery $.ajax 调用另一个控件的操作
- 非常简单的幻灯片放映,带有上一个和下一个控件
- 自定义指令如何知道它是否已单击另一个控件
- Cakephp 2.5:使用Cake控制器在js,css,images上添加控件
- Javascript在onclick上验证两个控件,但如果只有一个控件验证,则不保留值
- jQuery的函数不依赖于另一个控件的值
- 如何向幻灯片添加下一个和上一个控件
- 焦点在另一个控件上,但按enter键会按默认按钮