標籤: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 動畫初探