【发布时间】:2015-02-02 18:26:27
【问题描述】:
我有一个非常基本的幻灯片如下:
HTML
<div id="slideshow">
<img class="slide" src="img/slideshow-1.png" >
<img class="slide" src="img/slideshow-2.png" >
<img class="slide" src="img/slideshow-3.png" >
</div>
JS
$(function(){
var $slides = $(".slide"); //slides
var currentSlide = 0; //keep track on the current slide
var stayTime = 3; //time the slide stays
var slideTime = 1.3; //fade in / fade out time
TweenLite.set($slides.filter(":gt(0)"), {autoAlpha:0}); //we hide all images after the first one
TweenLite.delayedCall(stayTime, nextSlide); //start the slideshow
function nextSlide(){
TweenLite.to( $slides.eq(currentSlide), slideTime, {autoAlpha:0} ); //fade out the old slide
currentSlide = ++currentSlide % $slides.length; //find out the next slide
TweenLite.to( $slides.eq(currentSlide), slideTime, {autoAlpha:1} ); //fade in the next slide
TweenLite.delayedCall(stayTime, nextSlide); //wait a couple of seconds before next slide
}
});
如您所见,它只是将每个图像显示 3 秒(停留时间),然后将其淡出。假设我想保留第一个图像 8 秒,第二个 6.5 秒,第三个 3 秒。我的意思是所有图像的逗留时间都不相同。如何在 GSAP 或 Javascript 中实现这一点?
【问题讨论】:
-
你的意思是,你怎么能减少
stayTime参数? -
不,我的意思不是按固定间隔调用函数,而是按不同间隔调用它。
标签: javascript timing gsap