【问题标题】:How to adjust the speed in JQuery animation slide?如何在 JQuery 动画幻灯片中调整速度?
【发布时间】:2016-08-01 00:12:50
【问题描述】:

我有一张幻灯片正在快速转动,我需要帮助弄清楚如何减慢它。任何帮助将不胜感激!

[http://catchieconcepts.com/][1]

这就是全部代码

jQuery(document).ready(function($){
	var w,mHeight,tests=$("#testimonials");
	w=tests.outerWidth();
	mHeight=0;
	tests.find(".testimonial").each(function(index){
		$("#t_pagers").find(".pager:eq(0)").addClass("active");	//make the first pager active initially
		if(index==0)
			$(this).addClass("active");	//make the first slide active initially
		if($(this).height()>mHeight)	//just finding the max height of the slides
			mHeight=$(this).height();
		var l=index*w;				//find the left position of each slide
		$(this).css("left",l);			//set the left position
		tests.find("#test_container").height(mHeight);	//make the height of the slider equal to the max height of the slides
	});
});



$(".pager").on("click",function(e){	//clicking action for pagination
e.preventDefault();
next=$(this).index(".pager");
clearInterval(t_int);	//clicking stops the autoplay we will define later
moveIt(next);
});



function moveIt(next){	//the main sliding function
	var c=parseInt($(".testimonial.active").removeClass("active").css("left"));	//current position
	var n=parseInt($(".testimonial").eq(next).addClass("active").css("left"));	//new position
	$(".testimonial").each(function(){	//shift each slide
		if(n>c)
			$(this).animate({'left':'-='+(n-c)+'px'});
		else
			$(this).animate({'left':'+='+Math.abs(n-c)+'px'});
	});
	$(".pager.active").removeClass("active");	//very basic
	$("#t_pagers").find(".pager").eq(next).addClass("active");	//very basic
}

【问题讨论】:

    标签: jquery animation slide


    【解决方案1】:

    jQuery animate 有 ja 持续时间参数。例如:

    $(this).animate({'left':'-='+(n-c)+'px'}, 1000);
    

    持续时间以毫秒为单位,默认设置为 400 毫秒。

    【讨论】:

    • 谢谢!这减慢了从一张幻灯片到下一张幻灯片的转换速度。
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 2018-07-10
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 2015-04-21
    • 1970-01-01
    • 2012-04-30
    相关资源
    最近更新 更多