我的客户希望他们网站上的这个“赞助商”滑块可以滚动、随机化或淡入淡出。我尝试了不同的方法来实现所有这些,但没有任何效果。现在,滑块由设置为“.click”命令的按钮控制。有没有办法用Javascript添加动画,我需要改变什么才能做到这一点?如果不是动画,有没有办法用Javascript随机化页面加载上的数组?我一直在尝试输入不同的更改,但没有任何效果。我觉得也许我需要“关闭其他东西”才能让它们工作......
我是 Javascript 的新手,所以我会很感激一些帮助。
这是代码:
// ============
// = SPONSORS =
// ============
if($('#sponsors').length>0){
// let's make sure our logos are centered
$(window).load(function(){
$('#sponsor-logos li').each(function(){
wrapper = $(this).find('span.logo');
wrapper_height = wrapper.height();
sponsor_logo = $(this).find('img');
total_height = 84;
logo_height = sponsor_logo.height();
buffer = Math.floor(((total_height - logo_height) / 2));
wrapper.css('paddingTop',buffer + 'px').height(wrapper_height-buffer);
});
});
window_width = 656;
slide_duration = 500;
// get our arrows on there
$('#sponsors .inner').prepend('<a class="prev" href="#">Prev</a>').append('<a class="next" href="#">Next</a>');
// set our width
thumbs = $('#sponsor-logos');
thumbs.width(thumbs.children().length*164);
thumbs.wrap('<div class="slider"></div>');
// hook the arrows
$('#sponsors a.prev').click(function(){
thumbs = $('#sponsor-logos');
if((Math.abs(parseInt(thumbs.css('left').replace('px',''),10)))>1){
if(!thumbs.data('animating')){
thumbs.data('animating',true);
thumbs.animate(
{left:'+='+window_width+'px'},
slide_duration, 'swing', function(){
thumbs.data('animating',false);
}
);
}
}else{
// already too far, we'll bounce for feedback
if(!thumbs.data('animating')){
thumbs.data('animating',true);
thumbs.animate(
{left:'+=15px'},
(slide_duration/5), 'swing', function(){
thumbs.animate(
{left:'-=15px'},
(slide_duration/5), 'swing', function(){
thumbs.data('animating',false);
}
);
}
);
}
}
return false;
});
$('#sponsors a.next').click(function(){
thumbs = $('#sponsor-logos');
if(thumbs.width() - window_width - Math.abs(parseInt(thumbs.css('left').replace('px',''),10)) > 150){ // 150 represents at least one thumb (194 to be exact)
if(!thumbs.data('animating')){
thumbs.data('animating',true);
thumbs.animate(
{left:'-='+window_width+'px'},
slide_duration, 'swing', function(){
thumbs.data('animating',false);
}
);
}
}else{
// already too far, we'll bounce for feedback
if(!thumbs.data('animating')){
thumbs.data('animating',true);
thumbs.animate(
{left:'-=15px'},
(slide_duration/5), 'swing', function(){
thumbs.animate(
{left:'+=15px'},
(slide_duration/5), 'swing', function(){
thumbs.data('animating',false);
}
);
}
);
}
}
return false;
});
}