我的 jQuery 滑块运行良好,但存在错误,它有时不会在下次或上一次单击时显示图像
my jquery slider is running well but there is bug that it sometimes does'nt shows images on next or prev click
找到了播放和停止滑块的解决方案。但是现在问题出在我的下一个和上一个链接上一个链接上,这些链接有时不显示任何图像。我的代码在http://jsfiddle.net/yogesh84/ftkLd/12/
var slides;
var cnt;
var amount;
var i;
var x;
var timer;
slides = jQuery('#my_slider').children();
cnt = jQuery('#counter');
amount = slides.length;
i=amount;
cnt.text(i+' / '+amount);
function run_prev() {
jQuery(slides[i]).fadeOut(1000);
i--;
if (i <= 0) i = amount;
jQuery(slides[i]).fadeIn(1000);
// updating counter
cnt.text(i+' / '+amount);
}
x=0;
function run_next() {
// hiding previous image and showing next
jQuery(slides[x]).fadeOut(1000);
x++;
if (x >= amount) x = 0;
jQuery(slides[x]).fadeIn(1000);
cnt.text(x+1+' / '+amount);
}
/***********start and stop functions***************/
function run() {
// hiding previous image and showing next
jQuery(slides[x]).fadeOut(1000);
x++;
if (x >= amount) x = 0;
jQuery(slides[x]).fadeIn(1000);
timer = setTimeout(run,2000);
}
function MySlider() {
timer = setTimeout(run,2000);
}
function stoper() {
clearTimeout(timer);
}
/***********end start and stop functions***************/
function slide_show(){
var timer;
if(jQuery('#slide_show').html()=='Play Slideshow')
{
jQuery('#slide_show').html('Stop Slideshow');
MySlider();
}
else
{
jQuery('#slide_show').html('Play Slideshow');
stoper()
}
}
// custom initialization
jQuery('#prev2').on("click",run_prev);
jQuery('#next2').on("click",run_next);
jQuery('#slide_show').on("click",slide_show);
我想你忘了设置timer
您在顶部声明:timer
但它永远不会被填充。
所以我认为你应该这样做:
timer = setTimeout( run, inetrval );
也把函数放在 Run() 之外
function run() {
}
if ( inetrval > 0 ) {
alert( inetrval );
run();
timer = SetTimeOut( run, inetrval )
}
相关文章:
- 根据Angular.JS上一次的内容禁用选择
- 在上一次响应时隐藏Qualtrics项目-Javascript
- 如何在Javascript中设置函数在上一次结束时启动
- 您可以在节点.js上一次运行多个应用程序吗?
- AJAX在数组循环中调用,只在上一次完成后调用next
- 为什么这个 JavaScript switch 语句(在 for 循环内)保留了上一次迭代的值
- 在 html 页面上一次播放一个视频
- 如何使用上一次调用的数据进行第二次 JS .post 调用
- 如何在上一次 JQuery 调用后访问 DOM
- 在一个页面上一次显示所有“标题”工具提示
- 我的 jQuery 滑块运行良好,但存在错误,它有时不会在下次或上一次单击时显示图像
- 如何在 converse.js 上一次登录多个用户
- 创建不会中断上一次调用的重复动画
- 让循环等待,直到上一次传递完成
- Node JS-记录工作集群上一次异常
- JSTL:如何获取Map的上一次和下一次迭代元素
- 为什么函数只运行一次?在上一次调用完成后,尝试使用计数器函数多次运行函数
- 安卓:根据上一次活动列表中的选择,修改本地静态html加载的JS
- 视差下一次和上一次导航
- 在单个网页上一次显示一个调查声明的有效方式