js 動畫初探

來源:互聯網
上載者:User

標籤:style   blog   io   ar   color   os   sp   on   div   

直接上代碼

幾個參數和函數:

 

CSS

absolute:

絕對位置,他是參照瀏覽器的左上方,配合TOP、RIGHT、BOTTOM、LEFT(下面簡稱TRBL)進行定位,在沒有設定TRBL,預設依據父級的做標原始點為原始點。可脫離文檔流。要啟用物件的絕對(absolute)定位,必須指定 left , right , top , bottom 屬性中的至少一個,並且設定此屬性值為 absolute 。

relative:

 相對定位,他是參照父級的原始點為原始點,無父級則以BODY的原始點為原始點,配合TRBL進行定位,當父級內有padding等CSS屬性時,當前級的原始點則參照父級 內容區的原始點進行定位。

 

 

JQUERY

 

animate("style","speed"):該方法通過CSS樣式將元素從一個狀態改變為另一個狀態。

find():找到某個方法。

 

下面demo示範了滑鼠划過圖片出現內容的例子。

主要思想為先把  .title  左移覆蓋,然後通過滑鼠 事件 animate() 方法出現在圖片中。

 

 

 1 <!DOCTYPE html> 2 <html> 3 <head lang="en"> 4     <meta charset="UTF-8"> 5     <title></title> 6     <style> 7         .brands-list { 8             width: 480px; 9             height: 350px;10             overflow: hidden;11             margin: 20px auto 0 auto;12         }13         .brands-list li a {14             position: relative;15             height: 104px;16             display: block;17             cursor: pointer; }18         .brands-list li a .title19         { z-index: 2;20             position: absolute;21             bottom: 10px;22             left: -160px;23             width: 150px;24             height: 20px;25             padding: 0 0 0 10px;26             color: #f1e8eb;27             line-height: 17px;28             font-size:12px;}29   </style>30     <script src="js/jquery.js"></script>    31 </head>32 <body>33   <div class="brands-list">34       <ul>35           <li><a href="xx"><img src="pic_2.jpg" ><span class="title">TEST</span>36       </a></li>37       </ul>38   </div>39 </body>40 <script>41     $(function(){42         $(".brands-list li a").hover(function(){43             $(this).find(".title").animate({left:‘0px‘});44         },function(){45             $(this).find(".title").animate({left:‘-160px‘});46         });47     });48 </script>49 </html>

 

 方法獲得當前元素集合中每個元素的後代,通過選取器、jQuery 對象或元素來篩選。

js 動畫初探

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.