鼠標移入/移出改變圖片透明度_jQuery效果

enter image description here

瀏覽聚美優品的時候看到的這個效果,鼠標移入圖片後,當前圖爲高亮,*圖片爲灰色顯示,移出圖片區域後,圖片從新變爲高亮。挺繞口的,直接上代碼,你們預覽看下就曉得了,這種效果貌似電商網站用的還比較多。 代碼圖片直接用的聚美優品的,在此說明一下。 原本想用javascript寫的,有思路,可是掌握不熟練,無從下手,遂改用jQuery寫,代碼很簡單,一看便可明白。javascript

小知識點:css

1.jQuery中鼠標通過爲mouseover,鼠標離開爲mouseout。html

2.透明度設置的css代碼:opacity:0.5; filter:alpha(opacity=50); 代碼:java

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<style type="text/css">
*{margin:0; padding:0;}
li{ list-style:none;}

#top_banner{ width:400px;}
#top_banner li{  }
#top_banner li a{ position:relative; display:block; width:190px; height:150px;float: left;margin-right:10px; margin-bottom:10px;}
.mask_Layout{ width:190px; height:150px; position:absolute; left:0; top:0;}
.cur .mask_Layout{
     background:#000;
    opacity:0.5;
    filter:alpha(opacity=50);
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    $oLi=$('#top_banner ul li');
    $oA=$('#top_banner ul li a');

    $oLi.mouseover(function(){
        $oLi.addClass('cur');
        $(this).removeClass('cur');
        }).mouseout(function(){
            $oLi.removeClass('cur');
            })

    })
</script>

</head>

<body>
<div id="top_banner">
    <ul>
        <li>
            <a href="#">
                <img width="190" height="150" src="http://images.jumei.com/banner/63/new_mall_show/484_0.jpg" alt="歐萊雅">
                <div class="mask_Layout"></div>
            </a>
         <li>
             <a target="_blank" href="#">
                <img width="190" height="150" src="http://images.jumei.com/banner/63/new_mall_show/484_1.jpg" alt="絲塔芙">
                <div class="mask_Layout"></div>
             </a>
         </li>
         <li>
            <a target="_blank" href="#">
                <img width="190" height="150" src="http://images.jumei.com/banner/63/new_mall_show/863_13.jpg" alt="曼秀雷敦">
                <div class="mask_Layout"></div>
            </a>
         </li>
         <li>
            <a target="_blank" href="#">
                <img width="190" height="150" src="http://images.jumei.com/banner/63/new_mall_show/484_2.jpg" alt="佰草集">
                <div class="mask_Layout"></div>
            </a>
        </li>
    </ul>
</div>
</body>
</html>

轉載自:http://www.9958.pw/post/html_img_mouseoutjquery

相關文章
相關標籤/搜索