鼠标移入/移出改变图片透明度_jQuery效果
浏览聚美优品的时候看到的这个效果,鼠标移入图片后,当前图为高亮,*图片为灰色显示,移出图片区域后,图片重新变为高亮。挺绕口的,直接上代码,大家预览看下就晓得了,这种效果貌似电商网站用的还比较多。代码图片直接用的聚美优品的,在此说明一下。本来想用javascript写的,有思路,但是掌握不熟练,无从下手,遂改用jQuery写,代码很简单,一看即可明白。
<!--more-->小知识点:
1.jQuery中鼠标经过为mouseover,鼠标离开为mouseout。
2.透明度设置的css代码:opacity:0.5; filter:alpha(opacity=50);代码:
<!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>
相关推荐
EdwardSiCong 2020-11-23
85477104 2020-11-17
hhanbj 2020-11-17
81427005 2020-11-11
seoppt 2020-09-13
honeyth 2020-09-13
WRITEFORSHARE 2020-09-13
84483065 2020-09-11
momode 2020-09-11
85477104 2020-08-15
83510998 2020-08-08
82550495 2020-08-03
tthappyer 2020-08-03
84901334 2020-07-28
tthappyer 2020-07-25
TONIYH 2020-07-22
tztzyzyz 2020-07-20
83510998 2020-07-18
81463166 2020-07-17