jQuery hover事件滑鼠滑過圖片半透明標題文字滑動顯示隱藏

來源:互聯網
上載者:User

標籤:des   style   http   color   java   os   io   檔案   

1、效果及功能說明 

hover事件製作產品圖片滑鼠滑過圖片半透明,標題文字從左至右滑動動畫移動顯示隱藏 

2、實現原理 

首先把效果都隱藏,然後定義一個偽類來觸發所有的效果,接下來當觸發偽類後會有一個遍曆停止所有的效果,從新觸發效果就是標題的從左邊淡出和背景顏色的變化,當滑鼠離開圖片後觸發一個遍曆,停止所有動畫標題回到原處不見,背景顏色變回原樣 

主要的方法 

$(".section  ul li").hover(function()  

//偽類的觸發  

$(this).find(".rsp").stop().fadeTo(500,0.5)  

$(this).find(".text").stop().animate({left:‘0‘}, {duration: 500})  

//這兩段就是標題的淡出和背景顏色的改變  

$(this).find(".rsp").stop().fadeTo(500,0)  

$(this).find(".text").stop().animate({left:‘318‘}, {duration: "fast"})  

$(this).find(".text").animate({left:‘-318‘}, {duration: 0})  

//這三段就讓標題回放到原來的位置上去,讓背景顏色回到原樣  



3、 




4、運行環境 

IE6 IE7 IE8及以上 Firefox 和 Google Chrome遊覽器下都可實現 


5、所有圖片的壓縮包建立一個檔案後將包解壓放進檔案夾圖片的壓縮包在頁面的最下方可以看到並下載下載後無需修改檔案夾名因為本身就已經寫好了和html5內的路徑相吻合 

6、將建立html檔案儲存的時候將編碼類別型換成(UTF-8有簽名)這樣可以讓部分中文正常的顯示出來,將檔案類型(T)換成(所有檔案(*.*)),將html5和解壓後的圖片檔案夾放在同一個檔案夾內效果 


7、代碼[html5] 

<!DOCTYPE htm>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>

<style type="text/css">
*{margin:0;padding:0;list-style-type:none;}
a,img{border:0;}
body{font:12px/180% Arial, Helvetica, sans-serif, "新宋體";}
.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden;}
.clearfix{display:inline-table;}/* Hides from IE-mac \*/
*html .clearfix{height:1%;}
.clearfix{display:block;}/* End hide from IE-mac */
*+html .clearfix{min-height:1%;}
/* section */
.section{width:981px;margin:40px auto 0 auto;overflow:hidden;}
.section ul{width:996px;}
.section ul li{float:left;margin-right:14px;margin-bottom:13px;display:inline;width:318px;height:343px;overflow:hidden;position:relative;}
.section ul li .photo{width:318px;height:343px;overflow:hidden;}
.section .rsp{width:318px;height:343px;overflow:hidden;position: absolute;background:#000;top:0px;left:0px;}
.section .text{position:absolute;width:318px;height:343px;left:-318px;top:0px;overflow:hidden;}
.section .text h3{width:318px;margin-top:130px;height:55px;line-height:55px;text-align:center;color:#FFFFFF;background:#000000;font-family:"microsoft yahei";font-size:26px;}
</style>

<div class="section">
<ul class="clearfix">
<li>
<div class="photo"><img src="images/index_28.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="http://www.17sucai.com/"><h3>布品展示</h3></a></div>
</li>
<li>
<div class="photo"><img src="images/index_30.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="http://www.17sucai.com/"><h3>新品縱覽</h3></a></div>
</li>
<li>
<div class="photo"><img src="images/index_32.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="http://www.17sucai.com/"><h3>靈感街拍</h3></a></div>
</li>
<li>
<div class="photo"><img src="images/index_36.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="about.asp"><h3>公司故事</h3></a></div>
</li>
<li>
<div class="photo"><img src="images/index_29.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="http://www.17sucai.com/"><h3>留言</h3></a> </div>
</li>
<li>
<div class="photo"><img src="images/index_38.jpg" width="318" height="343" /></div>
<div class="rsp"></div>
<div class="text"><a href="http://www.17sucai.com/"><h3>聯絡我們</h3></a></div>
</li>
</ul>
<div class="clear"></div>
</div>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript">
$(document).ready(function(){
//定義一個可以啟用所有函數的方法

$(".section ul li .rsp").hide();
//獲得隱藏元素方法

$(".section ul li").hover(function(){
//定義一個偽類滑鼠觸及事件
$(this).find(".rsp").stop().fadeTo(500,0.5)
//當滑鼠移動到圖片上時通過遍曆停止所有啟動並執行動畫,獲得一個淡出事件
$(this).find(".text").stop().animate({left:‘0‘}, {duration: 500})
//當滑鼠移動到圖片上時通過遍曆停止所有啟動並執行動畫,在移動一個動畫讓標題出從左邊出現
},function(){
//在jquery 在定義一個方法
$(this).find(".rsp").stop().fadeTo(500,0)
//當滑鼠離開是通過遍曆停止動畫在讓淡出效果回去
$(this).find(".text").stop().animate({left:‘318‘}, {duration: "fast"})
//通過遍曆停止動畫後,在觸發一個動畫讓原本出現的標題開始回收,讓背景顏色變化正常
$(this).find(".text").animate({left:‘-318‘}, {duration: 0})
//通過遍曆制動動畫,發齣動畫讓標題回到原位,讓背景值變回0
});

});
</script>

</body>
</html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.