CSS Sprite (JS)_html/css_WEB-ITnose
HTML
1 <body> 2 <!-- ul.sprite>li*5>s.s-icon+a{CSS Sprite} --> 3 <!-- 以上是Sublime Text快速拼写 --> 4 <ul class="sprite"> 5 <li><s class="s-icon"></s><a href="">CSS Sprite</a></li> 6 <li><s class="s-icon"></s><a href="">CSS Sprite</a></li> 7 <li><s class="s-icon"></s><a href="">CSS Sprite</a></li> 8 <li><s class="s-icon"></s><a href="">CSS Sprite</a></li> 9 <li><s class="s-icon"></s><a href="">CSS Sprite</a></li>10 <div class="clear"></div>11 </ul>12 </body>
登入後複製
CSS
1 <style> 2 body { background-color: #fc0; color:#333;} 3 * {margin:0; padding:0;} 4 ul,li {list-style: none;} 5 a { color:#f00; font-weight: bold; text-decoration: none;} 6 .sprite {margin:0 auto; width:1000px; padding-top: 50px;} 7 .sprite li {float:left; margin-left: 50px; text-align: center; cursor:pointer; } 8 .sprite li s { display: block; width:132px; height:112px; background:url(all.png) no-repeat; } 9 .clear { clear:both;}10 </style>
登入後複製
JS
1 <script src="http://code.jquery.com/jquery-latest.js"></script> 2 <script> 3 $(function () { 4 var iconH = $(".sprite").find("s").height(), 5 //找出存放图片的容器的高度; 6 triggerLi = $(".sprite").children("li"); 7 //找出每一个li,放到一个数组中; 8 //console.log(iconH); 9 //在控制台打印出容器的高度;10 triggerLi.each(function () {11 //遍历数组中的每一个li12 var $this = $(this),13 //声明变量赋值当前的li;14 $index = $this.index();15 //声明变量保存当前li的index值;16 //console.log($index);17 //在控制台打印出每一个li的index值;18 //console.log(iconH*$index);19 //得出每一个图片对应的position值;20 $this.children("s").css("background-position","0 -"+iconH*$index+"px");21 //利用js遍历出每一个s标签的背景图片;22 $this.hover(function() {23 //鼠标移入24 $this.children("s").css("background-position","-132px -"+iconH*$index+"px");25 }, function() {26 //鼠标移出27 $this.children("s").css("background-position","0 -"+iconH*$index+"px");28 });29 })30 })31 </script>
登入後複製
IMG(右键保存即可,重命名all.png)
SHOW
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
2 週前
By 尊渡假赌尊渡假赌尊渡假赌
倉庫:如何復興隊友
4 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
擊敗分裂小說需要多長時間?
3 週前
By DDD
R.E.P.O.保存文件位置:在哪里以及如何保護它?
3 週前
By DDD

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

我如何使用html5&lt; time&gt; 元素以語義表示日期和時間?
