遮罩层特效(根据鼠标进入离开方向出现)

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>遮罩层特效(根据鼠标进入离开方向出现)</title>
<script src="../../js/jquery-1.7.2.js"></script>
<script>
$(function(){
 var $li=$(".wrap>ul>li");
 $li.each(function(index, element) {
     var $this=$(this);
     var $cover=$this.find(".cover");
     $this.bind("mouseenter mouseleave",function(e){
        var w = $(this).width();
        var h = $(this).height();
        /* 判断移动方向direction有 0 1 2 3四个值代表4个方向 */
        var x = (e.pageX - this.offsetLeft - (w / 2)) * (w > h ? (h / w) : 1);
        var y = (e.pageY - this.offsetTop - (h / 2)) * (h > w ? (w / h) : 1);
        var direction = Math.round((((Math.atan2(y, x) * (180 / Math.PI)) + 180) / 90) + 3) % 4;
    
        var eventType = e.type;
        var dirName = new Array(‘上方‘,‘右侧‘,‘下方‘,‘左侧‘);
        var name=dirName[direction];
        if(eventType == ‘mouseenter‘){
            switch(name){
                case "上方": $cover.css({top:"-100%",left:0});break;
                case "右侧": $cover.css({left:"100%",top:0});break;
                case "下方": $cover.css({top:"100%",left:0});break;
                case "左侧": $cover.css({left:"-100%",top:0});break;
            }
            $cover.stop().animate({top:0,left:0},"slow");
        }else{
            switch(name){
                case "上方": $cover.stop().animate({top:"-100%",left:0},"fast");break;
                case "右侧": $cover.stop().animate({left:"100%",top:0},"fast");break;
                case "下方": $cover.stop().animate({top:"100%",left:0},"fast");break;
                case "左侧": $cover.stop().animate({left:"-100%",top:0},"fast");break;
            }
        }
    });
    })
})
</script>

<style>
.wrap{width:1040px; margin:0 auto;}
.wrap ul li{list-style:none; float:left; width:490px; position:relative;}
.wrap ul li .imgcover{ position:relative; overflow:hidden;margin:10px;}
.wrap ul li .imgcover img{ position:relative;}
.wrap
ul li .imgcover .cover{ width:100%;height:300px; background:#000;
opacity:.8; filter:alpha(opacity=80); position:absolute;}
.wrap ul li .imgcover .cover .name{ font-size:30px; font-weight:bold;color:#fff;top:15%; text-align:center; position:relative;}
.cyclist{display:block;position:relative;top:20%;margin:20px 0; position:relative;width:67px; margin:0 auto;}
</style>
</head>

<body>
<div class="wrap">
<ul>
    <li>
        <div class="imgcover">
            <img src="01.jpg" height="623"/>
            <div class="cover" style="height:623px;">
                <p class="name">Climber‘s Delight</p>
                <img alt="Brad Feld" src="02.png" class="cyclist">
            </div>
        </div>
    </li>
    <li>
        <div class="imgcover">
            <img src="01.jpg" />
            <div class="cover">
                <p class="name">Climber‘s Delight</p>
                <img alt="Brad Feld" src="02.png" class="cyclist">
            </div>
        </div>
    </li>
    <li>
        <div class="imgcover">
            <img src="01.jpg" />
            <div class="cover">
                <p class="name">Climber‘s Delight</p>
                <img alt="Brad Feld" src="02.png" class="cyclist">
            </div>
        </div>
    </li>
    <li>
        <div class="imgcover">
            <img src="01.jpg" />
            <div class="cover">
                <p class="name">Climber‘s Delight</p>
                <img alt="Brad Feld" src="02.png" class="cyclist">
            </div>
        </div>
    </li>
    <li>
        <div class="imgcover">
            <img src="01.jpg" />
            <div class="cover">
                <p class="name">Climber‘s Delight</p>
                <img alt="Brad Feld" src="02.png" class="cyclist">
            </div>
        </div>
    </li>
</ul>
</div>
</body>
</html>
附件:01.jpg   02.png

时间: 2024-08-29 07:02:00

遮罩层特效(根据鼠标进入离开方向出现)的相关文章

ajax异步加载遮罩层特效

<!doctype html> <html> <head> <title>遮罩层(正在加载中)</title> <meta charset="utf-8" /> <style> #cover{ display:none; position:fixed; z-index:1; top:0; left:0; width:100%; height:100%; background:rgba(0, 0, 0,

简单的CSS3鼠标滑过图片标题和遮罩层动画特效

这是一款使用CSS3制作的简单的鼠标滑过图片标题和遮罩层动画特效.该鼠标滑过特效通过 CSS3transitions 和 transform 属性,在鼠标滑过图片时制作遮罩层和图片标题动画效果. 在线预览   源码下载 使用方法 HTML结构 该鼠标滑过图片特效的HTML结构非常简单:使用一个<div>元素作为图片遮罩层,在里面放置图片的描述信息. 1 2 3 4 5 6 7 8 <img src="img/01.jpg" alt=""> &

12种炫酷的CSS3鼠标滑过图片遮罩层动画特效

InContent是一款效果非常炫酷的CSS3鼠标滑过图片遮罩层动画特效.这组特效共有12种不同的鼠标滑过图片效果,分为滑动.旋转和翻转3大类.它可以在支持CSS3 transition和transform属性的现代浏览器中正常工作. 在线预览   源码下载 使用方法 使用该CSS3鼠标滑过图片遮罩层动画特效需要在页面中引入由SASS编译的sass-compiled.css文件或由LESS编译的less-compiled.css文件. <link rel="stylesheet"

WinForm特效:桌面上的遮罩层

一个窗体特效,帮你了解几个windows api函数.效果:windows桌面上增加一个简单的遮罩层,其中WS_EX_TRANSPARENT 比较重要,它实现了鼠标穿透的功能. [csharp] view plaincopy using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropServices; namespace WindowsApplication40 { pu

遮罩层小特效

今天学了一个遮罩层的特效,主要用在网页里面注册页面和登陆页面的使用: <style> * { margin: 0px; padding: 0px; } #mask { width: 100%; /*height: 500px;*/ background-color: black; opacity: 0.5; position: fixed; top: 0px; left: 0px; z-index: 990; } #login { width: 300px; height: 200px; po

简单实用的鼠标滑过图片遮罩层动画jQuery插件

nsHover是一款简单实用的鼠标滑过图片遮罩层动画jQuery插件.该插件可以在图片或块级元素上制作鼠标滑过时的遮罩层动画效果,它可以设置遮罩层的前景色和背景色,可以制作圆形图片等,非常实用. 在线预览   源码下载 使用方法 使用该鼠标滑过插件需要引入jQuery和ns.hover.min.js文件. 1 2 <script src="js/jquery.min.js"></script> <script src="js/ns.hover.m

C#使用Windows API实现桌面上的遮罩层(鼠标穿透)

C#实现实现桌面上的遮罩层(鼠标穿透)主要通过一下几个API函数来实现:GetWindowLong,SetWindowLong,SetLayeredWindowAttributes.其中有一个Windows 消息 WS_EX_TRANSPARENT 比较重要,它实现了鼠标穿透的功能. 下面来看看完整的实现代码: using System; using System.Drawing; using System.Windows.Forms; using System.Runtime.InteropS

【回忆1314】鼠标离开方向检测

直接看效果点这里 <html> <head>鼠标离开方向检测</head> <body> <div id="msg">鼠标放到框上,然后移开.</div> <div id="wrap" style="width:200px; height: 100px; line-height:30px; margin: 100px auto; text-align: center; borde

转【js &amp; jquery】遮罩层实现禁止a、span、button等元素的鼠标事件

/*遮罩层代码 作用:通过遮罩层的方式防止表单提交次数过多 */ function MaskIt(obj){ var hoverdiv = '<div class="divMask" style="position: absolute; width: 100%; height: 100%; left: 0px; top: 0px; background: #fff; opacity: 0; filter: alpha(opacity=0);z-index:5;"