jQuery实现鼠标点击弹出渐变层的方法
更新时间:2015年07月09日 09:42:52 投稿:goldensun
这篇文章主要介绍了jQuery实现鼠标点击弹出渐变层的方法,jQuery是当下最具人气的JavaScript库,需要的朋友可以参考下
弹出层在实际应用中我们经常会碰到大量的弹出层效果,下面我来做一个基于jquery的简单的弹出层效果实例,各位朋友有兴趣可参考。
效果代码如下
在弹出层中下面是核心代码
<script type="text/javascript"> // 渐变弹出层 $(document).ready(function(){ var speed = 600;//动画速度 $("#race a").click(function(event){//绑定事件处理 event.stopPropagation(); var offset = $(event.target).offset();//取消事件冒泡 $("#racePop").css({ top:offset.top + $(event.target).height() + "px", left:offset.left });//设置弹出层位置 $("#racePop").show(speed);//动画显示 }); $(document).click(function(event) { $("#racePop").hide(speed) });//单击空白区域隐藏 $("#racePop").click(function(event) { $("#racePop").hide(speed) });//单击弹出层则自身隐藏 }); </script>
完整实例
<!-- 渐变弹出层 --> <div id="race"><a href="#">点击</a></div> <div id="racePop" class="raceShow">这里是弹出层效果</div> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script type="text/javascript"> // 渐变弹出层 $(document).ready(function(){ var speed = 600;//动画速度 $("#race a").click(function(event){//绑定事件处理 event.stopPropagation(); var offset = $(event.target).offset();//取消事件冒泡 $("#racePop").css({ top:offset.top + $(event.target).height() + "px", left:offset.left });//设置弹出层位置 $("#racePop").show(speed);//动画显示 }); $(document).click(function(event) { $("#racePop").hide(speed) });//单击空白区域隐藏 $("#racePop").click(function(event) { $("#racePop").hide(speed) });//单击弹出层则自身隐藏 }); </script> <style> body{margin:0 auto;font:12px/1.5 tahoma,arial,5b8b4f53;color:#828282;background:#fff} body,h1,h2,h3,h4,h5,h6,p,ul,li,dl,dt,dd{padding:0;margin:0;} li{list-style:none;}img{border:none;}em{font-style:normal;} a{color:#555;text-decoration:none;outline:none;blr:this.onFocus=this.blur();} a:hover{color:#000;text-decoration:underline;} body{font-size:12px;font-family:Arial,Verdana, Helvetica, sans-serif;word-break:break-all;word-wrap:break-word;} .clear{height:0;overflow:hidden;clear:both;} /* 渐变弹出层 */ #race{display:block;width:200px;height:50px;line-height:50px;text-align:center;background:#CCC;border:#555 1px solid;margin:10px auto} .raceShow{background-color:#f1f1f1;border:solid 1px #ccc;position:absolute;display:none;width:300px;height:100px;padding:5px;font-size:12px;} </style>
相关文章
基于JQuery和CSS3实现仿Apple TV海报背景视觉差特效源码分享
这是一款效果非常炫酷的jQuery和CSS3仿Apple TV海报背景视觉差特效。该视觉差特效在使用鼠标在屏幕上下左右移动的时候,海报中的各种元素以不同的速度运动,形成视觉差效果,并且还带有一些流光特效。2015-09-09jquery中cookie用法实例详解(获取,存储,删除等)
这篇文章主要介绍了jquery中cookie用法,结合实例详细分析了jQuery操作cookie的获取,存储,删除等操作,并附带了Jquery操作Cookie记录用户查询过信息实现方法,需要的朋友可以参考下2016-01-01jQuery Validation实例代码 让验证变得如此容易
众所周知,Jquery以其简洁性让无数人为之疯狂。现在我要像大家介绍一个jQuery Validation,一看到Validation大家肯定第一直观感觉就是这肯定是一个验证框架,没有错,本文就是基于jQuery Validation展开讨论。2010-10-10JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
在ajax中经常需要对元素的位置进行精确的定位,此时不仅需要获取元素自身的大小位置等属性。还需要知道页面、浏览器、滚动条等的长度和宽度。2010-01-01
最新评论