标签:
1,显示效果:
2,html结构
1 <div class="process_list-lpu"> 2 <div class="process_line"></div> 3 <div class="content_list"> 4 <ul> 5 <li><a href="javascipt:;">End customer get product<b>1</b></a> </li> 6 <li><a href="javascipt:;">Log in EFOSE website and present installation or maintenance requirements <b>2</b></a></li> 7 <li><a href="javascipt:;">EFOSE prefer contact service point<b>3</b></a> </li> 8 <li style="margin-left:115px;"><a href="javascipt:;">Customer contact service point to get service<b>4</b></a> </li> 9 <li><a href="javascipt:;">Customer pays the bill directly or EFOSE pays the maintenance cost<b>5</b></a> </li> 10 </ul> 11 <div class="clear"></div> 12 </div> 13 14 </div>
3,主要的css样式
.line-lpu{ height:55px; position:relative; width:100%; overflow:hidden;} .line-lpu span{ width:43px; height:46px; background:url(‘https://www.efose.com/images/banners/lpu_03.png‘) no-repeat; position:absolute;top:0;} .border-lpu{border-bottom:1px solid #959595; height:23px; } .join-lpu li{ width:19%; float:left; margin-right:8px;background:none; padding:0; } .join-lpu li a{ display:block; color:#606060; text-decoration:none; border:1px solid #959595; min-height:215px; padding:10px;position:relative; overflow:hidden;} .join-lpu li a:hover{border:1px solid #337ab7;} .join-lpu li b{ font-size:60px; position:absolute; bottom:7px; right:-1px; font-style:italic; color:#c7c7c7;} .clear{clear:both;} .step-lpu span{ background:url(‘https://www.efose.com/images/banners/icon-lpu.png‘) no-repeat; display:block; width:75px; height:65px; margin-left:28px;} .step-lpu .icon0{ background-position:0 0;} .step-lpu .icon1{ background-position:0 -70px;} .step-lpu .icon2{ background-position:0 -140px;} .step-lpu .icon3{ background-position:0 -204px; height:58px; margin-bottom:7px;} .step-lpu .icon4{ background-position:0 -260px;}
4,JavaScript的编写
1 <script type="text/javascript"> 2 //实例化animationHover对象 3 window.onload = function(){ 4 var ah = new animationHover(); 5 ah.init(); 6 }; 7 //初始化标签对象 8 function animationHover(){ 9 this.step = document.getElementById(‘step‘); 10 this.stepLi = this.step.getElementsByTagName(‘li‘); 11 this.line = document.getElementById(‘line‘); 12 this.attr = null; 13 this.timer = null; 14 this.target = null; 15 16 } 17 //初始化事件 18 animationHover.prototype.init=function(){ 19 This =this; 20 for(var i=0;i<this.stepLi.length;i++){ 21 this.stepLi[i].index=i; 22 //给li标签绑定事件 23 this.stepLi[i].onmouseover=function(e){ 24 var myIndex=this.index; 25 This.onOver(This.line,(myIndex*162+55)); 26 }; 27 this.stepLi[i].onmouseout=function(){ 28 This.line.style.left=myIndex*162+55+‘px‘; 29 }; 30 31 } 32 }; 33 //定义鼠标经过的处理函数 34 animationHover.prototype.onOver=function(obj,target){ 35 This=this; 36 clearInterval(this.timer); 37 This.target=target; 38 timer=setInterval(function(){ 39 var target=This.target; //停止的目标点 40 var attrValue=parseInt(This.getStyle(obj,‘left‘)); 41 var dx=target-attrValue; //距目标点的"路程" 42 var speed=1/10*dx; 43 speed=speed>0?Math.ceil(speed):Math.floor(speed); 44 //防止取整引起的抖动 45 if(target==attrValue) clearInterval(timer); 46 //如果到达目标点,关闭定时器 47 else{ 48 obj.style.left=attrValue+speed+‘px‘; 49 } 50 },100); 51 52 }; 53 //获取当前标签对象的css属性值 54 animationHover.prototype.getStyle =function(obj,attr){ 55 if(obj.currentStyle){ 56 return obj.currentStyle[attr]; 57 }else{ 58 return getComputedStyle(obj,false)[attr]; 59 } 60 }; 61 62 63 64 65 </script>
完整的html+css+javascript实现跟随鼠标移动显示选中效果
标签:
原文地址:http://www.cnblogs.com/liangsongbai/p/4866268.html