jquery實現點擊彈出層效果的簡單實例

彈出層在實際應用中我們經常會碰到大量的彈出層效果,下面我來做一個基於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>

完整實例

. 代碼如下:

<!– 漸變彈出層 –>
<p id="race"><a href="#">點擊</a></p>
<p id="racePop" class="raceShow">這裡是彈出層效果</p>

 

<script type="text/javascript" src="https://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>

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *