DIV CSS 佈局教程網

jQuery 實現滑鼠滑過遮罩並高亮顯示效果
編輯:JavaScript綜合知識     

滑鼠移過圖片時,讓目前這張保持明亮、其餘的則淡化變暗,這種「聚焦高亮」的效果在圖片牆上很常見。以下示範如何用 jQuery 實作。

完整程式碼:

<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>滑鼠滑過遮罩高亮效果</title>
<style>
*{padding:0;margin:0;}
ul,li{list-style:none;}
.picshow{float:left;padding:4px 0;width:760px;position:relative;}
.picshow li{float:left;height:160px;width:190px;opacity:0.9;}
.picshow li img{height:160px;width:190px;}
.picshow li a{display:block;}
</style>
<script type="text/javascript" src="https://jt.875.cn/js/jquery.js"></script>
<script type="text/javascript">
$(function() {
    var conAry = $("[name=h_light]");
    conAry.each(function(){
        var $this = $(this);
        var els = $("a", $this);
        els.each(function(){
            var el = $(this);
            el.mouseover(function() {
                els.css({ "opacity": 0.6});
                el.animate({ "opacity": 0.9 });
            });
        });
        $this.mouseout(function() {
            els.css("opacity", 1);
        });
    });
});
</script>
</head>
<body>
<ul class="picshow" name="h_light">
<li><a href="https://www.875.cn/" target="_blank"><img src="https://pic.875.cn/upload/2013-01-24/1634016671.jpg" ></a></li>
<li><a href="https://www.875.cn/" target="_blank"><img src="https://pic.875.cn/upload/2013-01-24/1634016671.jpg" ></a></li>
<li><a href="https://www.875.cn/" target="_blank"><img src="https://pic.875.cn/upload/2013-01-24/1634016671.jpg" ></a></li>
<li><a href="https://www.875.cn/" target="_blank"><img src="https://pic.875.cn/upload/2013-01-24/1634016671.jpg" ></a></li>
</ul>
</body>
</html>

效果預覽:

關鍵在於:滑鼠移入某張圖時,先把同群組的所有項目透明度調低,再用 animate 把當前項目平滑地提亮;移出整個群組後,再將全部還原為完全不透明。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved