jQuery實現(xiàn)的感應鼠標懸停圖片色彩漸顯效果
來源:易賢網(wǎng) 閱讀:868 次 日期:2015-03-06 11:16:49
溫馨提示:易賢網(wǎng)小編為您整理了“jQuery實現(xiàn)的感應鼠標懸停圖片色彩漸顯效果”,方便廣大網(wǎng)友查閱!

這篇文章主要介紹了jQuery實現(xiàn)的感應鼠標懸停圖片色彩漸顯效果,涉及jQuery中hover、find、css等方法的使用技巧,需要的朋友可以參考下

本文實例講述了jQuery實現(xiàn)的感應鼠標懸停圖片色彩漸顯效果。分享給大家供大家參考。具體實現(xiàn)方法如下:

代碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

<head>

<title>超個性的感應鼠標懸停圖片色彩漸顯效果</title>

<meta http-equiv="content-type" content="text/html;charset=gb2312">

<!--把下面代碼加到<head>與</head>之間-->

<style type="text/css">

ul.gallery {

width: 750px; /*--Adjust width according to your scenario--*/

list-style: none;

margin: 0; padding: 0;

}

ul.gallery li {

float: left;

margin: 10px 0 10px 25px;

padding: 0;

text-align: center;

border: 1px solid #ccc;

-moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/

-khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/

-webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/

display: inline; /*--Gimp Fix aka IE6 Fix - Fixes double margin bug--*/

}

ul.gallery li a.thumb {

width: 336px; /*--Width of image--*/

height: 240px; /*--Height of image--*/

border-bottom: 1px solid #ccc;

cursor: pointer;

}

ul.gallery li span { /*--Used to crop image--*/

width: 336px;

height: 240px;

overflow: hidden;

display: block;

}

ul.gallery li a.thumb:hover {

background: #333; /*--Hover effect for browser with js turned off--*/

}

ul.gallery li h2 {

font-weight: normal;

margin: 0;

padding: 10px;

background: #f0f0f0;

border-top: 1px solid #fff; /*--Subtle bevel effect--*/

}

ul.gallery li a {

text-decoration: none;

color: #777;

display: block;

font-size: 140%;

}

</style>

<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>

<script type="text/javascript">

$(document).ready(function() {

$("ul.gallery li").hover(function() { //On hover...

var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'

//Set a background image(thumbOver) on the <a> tag - Set position to bottom

$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});

//Animate the image to 0 opacity (fade it out)

$(this).find("span").stop().fadeTo('normal', 0 , function() {

$(this).hide() //Hide the image after fade

});

} , function() { //on hover out...

//Fade the image to full opacity

$(this).find("span").stop().fadeTo('normal', 1).show();

});

});

</script>

</head>

<body>

預覽效果時左下角會提示錯誤,而且看不到效果,刷新一下就可以看到效果了;當然,在實際使用中,不會出現(xiàn)這樣的問題。<br>

<!--把下面代碼加到<body>與</body>之間-->

<ul class="gallery">

<li>

<a href="#" class="thumb"><span><img src="/html/txdm_2/images/20100904/336240.jpg" alt=""></span></a>

<h2><a href="#">Sunflowa Media</a></h2>

</li>

</ul>

</body>

</html>

希望本文所述對大家的jQuery程序設計有所幫助。

更多信息請查看IT技術專欄

更多信息請查看腳本欄目
易賢網(wǎng)手機網(wǎng)站地址:jQuery實現(xiàn)的感應鼠標懸停圖片色彩漸顯效果

2026國考·省考課程試聽報名

  • 報班類型
  • 姓名
  • 手機號
  • 驗證碼
關于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡要咨詢 | 簡要咨詢須知 | 新媒體/短視頻平臺 | 手機站點 | 投訴建議
工業(yè)和信息化部備案號:滇ICP備2023014141號-1 云南省教育廳備案號:云教ICP備0901021 滇公網(wǎng)安備53010202001879號 人力資源服務許可證:(云)人服證字(2023)第0102001523號
聯(lián)系電話:0871-65099533/13759567129 獲取招聘考試信息及咨詢關注公眾號:hfpxwx
咨詢QQ:1093837350(9:00—18:00)版權所有:易賢網(wǎng)