html+css+javascript完成追随电脑鼠标挪动显示信息选

日期:2021-02-28 类型:科技新闻 

关键词:html网页制作,php网页制作,网页设计稿,网页编辑工具,学生网页设计模板

1,显示信息实际效果:

2,html构造

<div class="process_list-lpu">
                <div class="process_line"></div>
                <div class="content_list">
                    <ul>
                        <li><a href="javascipt:;">End customer get product<b>1</b></a> </li>
                        <li><a href="javascipt:;">Log in EFOSE website and present installation or maintenance requirements <b>2</b></a></li>
                        <li><a href="javascipt:;">EFOSE prefer contact service point<b>3</b></a> </li>
                        <li style="margin-left:115px;"><a href="javascipt:;">Customer contact service point to get service<b>4</b></a> </li>
                        <li><a href="javascipt:;">Customer pays the bill directly or EFOSE pays the maintenance cost<b>5</b></a> </li>
                    </ul>
                    <div class="clear"></div>
                </div>
            
            </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:⑴px; 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 ⑺0px;}
    .step-lpu .icon2{ background-position:0 ⑴40px;}
    .step-lpu .icon3{ background-position:0 ⑵04px; height:58px; margin-bottom:7px;}
    .step-lpu .icon4{ background-position:0 ⑵60px;}

4,JavaScript的撰写

<script type="text/javascript">
        //案例化animationHover目标
        window.onload = function(){
            var ah = new animationHover();  
            ah.init();
        }; 
        //原始化标识目标
        function animationHover(){
            this.step = document.getElementById('step');
            this.stepLi = this.step.getElementsByTagName('li');
            this.line = document.getElementById('line');
            this.attr = null;
            this.timer = null;
            this.target = null;
                            
            }
        //原始化恶性事件
        animationHover.prototype.init=function(){
            This =this;
            for(var i=0;i<this.stepLi.length;i++){
                this.stepLi[i].index=i;
                //给li标识关联恶性事件
                this.stepLi[i].onmouseover=function(e){    
                    var myIndex=this.index;
                    This.onOver(This.line,(myIndex*162+55));
                    };
                this.stepLi[i].onmouseout=function(){            
                   This.line.style.left=myIndex*162+55+'px';
                    };    
                
                }
            };
        //界定电脑鼠标历经的解决涵数
        animationHover.prototype.onOver=function(obj,target){
            This=this;
            clearInterval(this.timer);
            This.target=target;
            timer=setInterval(function(){
                var target=This.target; //终止的总体目标点
                var attrValue=parseInt(This.getStyle(obj,'left')); 
                var dx=target-attrValue; //距总体目标点的"路途"
                var speed=1/10*dx;
                speed=speed>0?Math.ceil(speed):Math.floor(speed); 
                            //避免取整引发的颤动
                if(target==attrValue) clearInterval(timer); 
                            //假如抵达总体目标点,关掉定时执行器
                else{
                    obj.style.left=attrValue+speed+'px';
                }
                },100);
                                    
            };
        //获得当今标识目标的css特性值
        animationHover.prototype.getStyle =function(obj,attr){                    
            if(obj.currentStyle){                
                return obj.currentStyle[attr];
            }else{
                return getComputedStyle(obj,false)[attr];
            }
            };    
</script>

总结

以上所述是网编给大伙儿详细介绍的html+css+javascript完成追随电脑鼠标挪动显示信息选定实际效果 ,期待对大伙儿有一定的协助,假如大伙儿有任何疑惑欢迎给我留言,网编会立即回应大伙儿的!