简体   繁体   English

Javascript / jQuery在两个图像之间滑动

[英]Javascript / jQuery flick between two images

I'm struggling with the timer part. 我正在为计时器部分苦苦挣扎。 I can replace one image with another easily with javascript by calling the function. 我可以使用javascript通过调用函数轻松地将一个图像替换为另一个图像。 What I want to be able to do is set a timer to sit and change the images at a specific interval (say 1 second). 我想要做的是设置一个计时器,以固定的时间间隔并更改图像(例如1秒)。

I've used jQuery to refresh an image every second before, but when I try and add a function inside to change the image, it just hangs. 我以前使用过jQuery每秒刷新一次图像,但是当我尝试在内部添加函数以更改图像时,它只是挂起。

you can use setinterval function of javascript: 您可以使用javascript的setinterval函数:

 setInterval(function,time); //ex: setInterval(myfunction,1000)

setInterval will also return a pointer to time which can be used later on to clearInterval setInterval还将返回一个指向时间的指针,以后可以将其用于clearInterval

var interval = setInterval(myfunction,1000);

later you can use: 以后您可以使用:

clearInterval(interval)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM