除非单击箭头,否则如何停止此图像滑块轮播中的所有动画?
轮播位于 http://www.indicatorwarehouse.com/index-3- 27-11.html
网站所有者想要做的是让图像滑块保持静止,除非有人单击绿色箭头,然后它只会移动一次。或者,他希望它非常缓慢地滑动,也许每 5 分钟滑动一次。该滑块的代码如下...请记住,我不知道这些代码的含义,我是一个 js 新手。非常感谢! :)
$(document).ready(function(){
$('#sliderGallery').Slider();
});
(function($){
$.fn.Slider = function(params){
var defaults = {
moveLeft: true,
onItem: false,
isAnimating: false,
timer: null
},
intialize = function(id){
/////////////////////////////////////////////////////////////
///// Bind Hover Events on Left & Right Buttons /////
/////////////////////////////////////////////////////////////
$('div#leftButton').hover(function(){
$(this).addClass('leftImageHov');
clearInterval(defaults.timer);
},function(){
$(this).removeClass('leftImageHov');
setTimer();
});
$('div#rightButton').hover(function(){
$(this).addClass('rightImageHov');
clearInterval(defaults.timer);
},function(){
$(this).removeClass('rightImageHov');
setTimer();
});
/////////////////////////////////////////////////////////////
///// Stop Animation on Hovering Items /////
/////////////////////////////////////////////////////////////
$('#canvas ul li').hover(function(){
clearInterval(defaults.timer);
},function(){
setTimer();
});
/////////////////////////////////////////////////////////////
///// Get Size of the #Canvas ul & Set It /////
/////////////////////////////////////////////////////////////
var li = $('#canvas ul li');
var liWidth = li.eq(0).width();
var liCount = li.length;
$('#canvas ul').css({width: liWidth*liCount + 'px', left: '0px'});
/////////////////////////////////////////////////////////////
///// Bind Click Event on the Left & Right Buttons /////
/////////////////////////////////////////////////////////////
var leftLimit = (liWidth*liCount) - $('div#canvas').width();
$('div#leftButton').click(function(){
if(!defaults.isAnimating)
Animate(liWidth, 600, leftLimit);
});
$('div#rightButton').click(function(){
if(!defaults.isAnimating)
Animate((-1*liWidth), 600, leftLimit);
});
setTimer();
},
setTimer = function(){
defaults.timer = setInterval(doAnimation, 30000 );
},
Animate = function(amount, time, leftLimit){
defaults.isAnimating = true;
var leftVal = $('div#canvas ul').css('left');
leftVal = leftVal.replace('px','');
leftVal = leftVal*1;
amount += leftVal;
/////////////////////////////////////////////////////////////
///// Range Check /////
/////////////////////////////////////////////////////////////
if(amount < (-1*leftLimit)) { amount = (-1*leftLimit); defaults.moveLeft = false; }
if(amount > 0) { amount = 0; defaults.moveLeft = true; }
$('div#canvas ul').animate({
left: amount
}, time, function() { defaults.isAnimating=false; });
},
/////////////////////////////////////////////////////////////
///// Animation /////
/////////////////////////////////////////////////////////////
doAnimation = function(){
var li = $('#canvas ul li');
var liWidth = li.eq(0).width();
var liCount = li.length;
var leftLimit = (liWidth*liCount) - $('div#canvas').width();
var animValue = liWidth*3;
if(defaults.moveLeft) animValue *= -1;
else animValue = leftLimit;
Animate(animValue, 0, leftLimit);
}
return this.each(function(){
intialize(this);
});
}
})(jQuery);
The carousel is located at http://www.indicatorwarehouse.com/index-3-27-11.html
What the site owner wants to do is have the image slider stay still unless someone clicks the green arrows, and then it will move just once. Alternatively, he wants it to slide VERY slownly, perhaps once every 5 minutes. The code for this slider is below...please bear in mind I have no clue what any of this code means, I'm a total novice with js. Thank you very much! :)
$(document).ready(function(){
$('#sliderGallery').Slider();
});
(function($){
$.fn.Slider = function(params){
var defaults = {
moveLeft: true,
onItem: false,
isAnimating: false,
timer: null
},
intialize = function(id){
/////////////////////////////////////////////////////////////
///// Bind Hover Events on Left & Right Buttons /////
/////////////////////////////////////////////////////////////
$('div#leftButton').hover(function(){
$(this).addClass('leftImageHov');
clearInterval(defaults.timer);
},function(){
$(this).removeClass('leftImageHov');
setTimer();
});
$('div#rightButton').hover(function(){
$(this).addClass('rightImageHov');
clearInterval(defaults.timer);
},function(){
$(this).removeClass('rightImageHov');
setTimer();
});
/////////////////////////////////////////////////////////////
///// Stop Animation on Hovering Items /////
/////////////////////////////////////////////////////////////
$('#canvas ul li').hover(function(){
clearInterval(defaults.timer);
},function(){
setTimer();
});
/////////////////////////////////////////////////////////////
///// Get Size of the #Canvas ul & Set It /////
/////////////////////////////////////////////////////////////
var li = $('#canvas ul li');
var liWidth = li.eq(0).width();
var liCount = li.length;
$('#canvas ul').css({width: liWidth*liCount + 'px', left: '0px'});
/////////////////////////////////////////////////////////////
///// Bind Click Event on the Left & Right Buttons /////
/////////////////////////////////////////////////////////////
var leftLimit = (liWidth*liCount) - $('div#canvas').width();
$('div#leftButton').click(function(){
if(!defaults.isAnimating)
Animate(liWidth, 600, leftLimit);
});
$('div#rightButton').click(function(){
if(!defaults.isAnimating)
Animate((-1*liWidth), 600, leftLimit);
});
setTimer();
},
setTimer = function(){
defaults.timer = setInterval(doAnimation, 30000 );
},
Animate = function(amount, time, leftLimit){
defaults.isAnimating = true;
var leftVal = $('div#canvas ul').css('left');
leftVal = leftVal.replace('px','');
leftVal = leftVal*1;
amount += leftVal;
/////////////////////////////////////////////////////////////
///// Range Check /////
/////////////////////////////////////////////////////////////
if(amount < (-1*leftLimit)) { amount = (-1*leftLimit); defaults.moveLeft = false; }
if(amount > 0) { amount = 0; defaults.moveLeft = true; }
$('div#canvas ul').animate({
left: amount
}, time, function() { defaults.isAnimating=false; });
},
/////////////////////////////////////////////////////////////
///// Animation /////
/////////////////////////////////////////////////////////////
doAnimation = function(){
var li = $('#canvas ul li');
var liWidth = li.eq(0).width();
var liCount = li.length;
var leftLimit = (liWidth*liCount) - $('div#canvas').width();
var animValue = liWidth*3;
if(defaults.moveLeft) animValue *= -1;
else animValue = leftLimit;
Animate(animValue, 0, leftLimit);
}
return this.each(function(){
intialize(this);
});
}
})(jQuery);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要设置动画幻灯片每 5 分钟更改
:
To set animation slide every 5 mins change:
to
要一一滑动,请尝试更改此设置:
这样:
To sliding one by one try to change this:
with this:
它有效..尝试一次
it works.. try this once