标签:io ar for div sp cti on c ef
从默认彩色化,到灰度化.
<div id="friendBox">
<a href=""><img src="images/friendPic2.jpg" /></a>
<a href=""><img src="images/friendPic2.jpg" /></a>
<a href=""><img src="images/friendPic2.jpg" /></a>
<a href=""><img src="images/friendPic2.jpg" /></a>
</div>
<script>
(function(){
var imgs=document.getElementById("friendBox").getElementsByTagName("img"),imgs_length=imgs.length,i=0;
var imgHover=function(theNode,theSrc){
return function(e){
var reg=/(?:\.jpg|\.gif|\.png)$/i;
var result=theSrc.match(reg);
var resultSrc="_gray"+result;
var newSrc=theSrc.replace(result,resultSrc);
theNode.setAttribute("src",newSrc);
}
};
var imgOut=function(theNode,theSrc){
return function(e){
theNode.setAttribute("src",theSrc);
}
};
for(i=0;i<imgs_length;i+=1){
var imgSrc=imgs[i].getAttribute("src");
imgs[i].onmouseover=imgHover(imgs[i],imgSrc);
imgs[i].onmouseout=imgOut(imgs[i],imgSrc);
}
})();
</script>
从默认灰度化,到彩色化.
<div id="friendBox" class="friendBox clearfix">
<a href=""><img src="images/friendPic2_gray.jpg" /></a>
<a href=""><img src="images/friendPic2_gray.jpg" /></a>
<a href=""><img src="images/friendPic2_gray.jpg" /></a>
<a href=""><img src="images/friendPic2_gray.jpg" /></a>
<a class="last" href=""><img src="images/friendPic2_gray.jpg" /></a>
</div>
<script>
(function(){
var imgs=document.getElementById("friendBox").getElementsByTagName("img"),imgs_length=imgs.length,i=0;
var imgHover=function(theNode,theSrc){
return function(e){
var newSrc=theSrc.replace(/_gray/,"");
theNode.setAttribute("src",newSrc);
}
};
var imgOut=function(theNode,theSrc){
return function(e){
theNode.setAttribute("src",theSrc);
}
};
for(i=0;i<imgs_length;i+=1){
var imgSrc=imgs[i].getAttribute("src");
imgs[i].onmouseover=imgHover(imgs[i],imgSrc);
imgs[i].onmouseout=imgOut(imgs[i],imgSrc);
}
})();
</script>
标签:io ar for div sp cti on c ef
原文地址:http://www.cnblogs.com/dingyuanxin/p/3979266.html