jquery實現(xiàn)點擊彈出層效果的簡單實例
彈出層在實際應用中我們經(jīng)常會碰到大量的彈出層效果,下面我來做一個基于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) });//單擊空白區(qū)域隱藏
$("#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) });//單擊空白區(qū)域隱藏
$("#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 ajax請求導出Excel表格的實現(xiàn)代碼
下面小編就為大家?guī)硪黄狫query ajax請求導出Excel表格的實現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06
淺析jQuery中調用ajax方法時在不同瀏覽器中遇到的問題
這篇文章主要介紹了jQuery中調用ajax方法時在不同瀏覽器中遇到的問題,因不同瀏覽器默認設置的不同造成的問題2014-06-06

