首頁 > web前端 > js教程 > 主體

基於jQuery實作滑鼠點擊導航選單水波動畫效果附原始碼下載_jquery

WBOY
發布: 2016-05-16 15:21:18
原創
1570 人瀏覽過

基於jQuery滑鼠點擊水波動畫垂直導航程式碼。這是一款基於jQuery+CSS3實現的帶有動畫效果的垂直導航列特效。效果圖如下:

效果展示    源碼下載

html代碼:

<div class="nav">
  <ul>
   <li><a>网站首页</a></li>
   <li><a>关于我们</a></li>
   <li><a>产品中心</a></li>
   <li><a>成功案例</a></li>
   <li><a>联系我们</a></li>
   <li><a>在线留言</a></li>
  </ul>
 </div>
 <script type="text/javascript" src="js/jquery.min.js"></script>
 <script type="text/javascript">
  //jQuery time
  var parent, ink, d, x, y;
  $(".nav ul li a").click(function (e) {
   parent = $(this).parent();
   //create .ink element if it doesn't exist
   if (parent.find(".ink").length == 0)
    parent.prepend("<span class='ink'></span>");
   ink = parent.find(".ink");
   //incase of quick double clicks stop the previous animation
   ink.removeClass("animate");
   //set size of .ink
   if (!ink.height() && !ink.width()) {
    //use parent's width or height whichever is larger for the diameter to make a circle which can cover the entire element.
    d = Math.max(parent.outerWidth(), parent.outerHeight());
    ink.css({ height: d, width: d });
   }
   //get click coordinates
   //logic = click coordinates relative to page - parent's position relative to page - half of self height/width to make it controllable from the center;
   x = e.pageX - parent.offset().left - ink.width() / 2;
   y = e.pageY - parent.offset().top - ink.height() / 2;
   //set the position and add class .animate
   ink.css({ top: y + 'px', left: x + 'px' }).addClass("animate");
  })
 </script>
登入後複製

以上程式碼是本文的核心程式碼,比較簡單,大家可以依照需求,適當的添加刪除程式碼。

來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!