之前写了个javascript动画对象里面的demo比较简单,这是一个比较完整的JS效果。代码很简单,通过修改position:absolute元素的left属性实现滑动切换。

点击这里查看淘宝活动广告滑动切换JS效果

JS代码:

(function(){
	//rentj1@163.com	  
	var left = 0;
	var slide = document.getElementById("slide-content");
	var options = document.getElementById("slide-options").getElementsByTagName("li");
	var width = 715;
	var active = 0;
	var length = options.length;
	slide.style.width = (width * options.length)+ "px";
	
	//绑定事件
	var onchange = function(index){
		//动画代码
	
		(index === undefined) ? left -= width : left = -(index * width);
		if(Math.abs(left) > (options.length-1)* width){
			left = 0;	
		}

		effect.animate(slide, { left: left }, 300, "easeIn",function(){

			options[active].className = "";												 
			active = Math.abs(left/width);
			options[active].className = "select";
																	
		});
	}
	
	
	
	var timer = setInterval(onchange ,3000);
	
	for(var i=0; i<length; i++) {
		
		(function(i){
				  
			options[i].onmouseover = function(){
				//alert(i)
				clearInterval(timer);
				onchange(i);
			};
			
			options[i].onmouseleave = function(){
				timer = setInterval(onchange ,3000);
				
			};
		
		})(i);
	}
	
}());

  

 

相关文章:

  • 2021-05-14
  • 2022-02-05
  • 2022-02-12
  • 2022-12-23
  • 2022-12-23
  • 2021-11-07
  • 2021-11-02
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2021-08-04
  • 2021-11-03
  • 2022-01-18
  • 2021-06-20
  • 2021-12-22
相关资源
相似解决方案