javascript鼠标滑过图片的方向进入透明背景效果
发布在前端菜鸟2016年8月2日view:2783BrettBat
在文章任何区域双击击即可给文章添加【评注】!浮到评注点上可以查看详情。

enter image description here function a2d(n){ return n*180/Math.PI; } function hoverDir(obj,ev){ var a=ev.clientX-(obj.offsetLeft+obj.offsetWidth/2); var b=obj.offsetTop+obj.offsetHeight/2-ev.clientY; return Math.round((a2d(Math.atan2(b,a))+180)/90)%4;

    }
    function through(obj){          
        obj.onmouseenter=function(ev){
            var oEvent=ev||event;
            var oS=this.children[0];
            var dir = hoverDir(obj,oEvent);             
            switch(dir){
                case 0:
                    oS.style.left = '-200px';
                    oS.style.top = 0;
                    break;
                case 1:
                    oS.style.left = 0;
                    oS.style.top = '200px';
                    break;
                case 2:
                    oS.style.left ='200px';
                    oS.style.top = 0;
                    break;
                case 3:
                    oS.style.left = 0;
                    oS.style.top ='-200px';
                    break;
            }               
            move(oS,{left:0,top:0},{duration:300,easeing:'linear'});                
        }
        obj.onmouseleave = function(ev){
            var oEvent = ev||event;
            var oS = this.children[0];
            var dir = hoverDir(obj,oEvent);
            switch(dir){
                case 0:
                    move(oS,{left:-200,top:0},{duration:300,easing:'linear'});
                    break;
                case 1:
                    move(oS,{left:0,top:200},{duration:300,easing:'linear'});
                    break;
                case 2:
                    move(oS,{left:200,top:0},{duration:300,easing:'linear'});
                    break;
                case 3:
                    move(oS,{left:0,top:-200},{duration:300,easing:'linear'});
                    break;
            }
        };
    }
    window.onload=function(){
        var oLi=document.getElementsByTagName("li");
        for(var i=0;i<oLi.length;i++){
            through(oLi[i])
        }

    }

前端菜鸟分享:javascript鼠标滑过图片的方向进入透明背景效果

评论
发表评论
暂无评论
WRITTEN BY
前端菜鸟
前端菜鸟是为前端初学者提供div+css、html5+css3、JavaScript、jquery、前端web开发、移动端html5开发集一体的前端知识以及前端资讯网站!
TA的新浪微博
PUBLISHED IN
前端菜鸟

和大家共同交流javascript技术

友情链接 大搜车前端团队博客
我的收藏