我的客户希望他们的网站上各滚动这个“赞助商”滑块,可以随机或者淡入和淡出。我尝试过不同的事情来完成所有这些事情,但没有任何效果。此时滑块由设置为“.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;
});
}
在'$( '#保荐徽标礼')。每个()',你声明变量作为隐含的全局。你也许应该使用VAR来宣布他们:'VAR包装= $(本).find(“span.logo”),...,缓冲= ...;'(用逗号每一个新的变量分离和结束的声明块一个分号)。 – jacob