不引人注目的鼠标图像交换与预加载
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了不引人注目的鼠标图像交换与预加载相关的知识,希望对你有一定的参考价值。
Needs object detection to be completely unobtrusive
function imageSwap(id) { var links = document.getElementById(id).getElementsByTagName("a"); var imgLoad = [] for(var i = 0; i < links.length; i++) { attachBehavior(links[i], i); } function attachBehavior(obj, iter) { var img = obj.getElementsByTagName('img')[0]; var imgSrc = img.getAttribute("src"); var ext = imgSrc.match(/.S{3}$/); var overSrc = imgSrc.replace(ext, "-over" + ext); // preLoad over states imgLoad[iter] = new Image(); imgLoad[iter].src = overSrc // use event listeners if appropriate obj.onmouseover = function(){ img.setAttribute("src", overSrc); } obj.onmouseout = function(){ img.setAttribute("src", imgSrc); } } } imageSwap("footer-links"); //all links inside the element with this id will receive mouseover behavior /* takes two image links "about.gif" and "about-over.gif" and swaps them on mouseover and mouseout Any image link in html page that you want to recieve mouseover behavior make sure image exists that has the name of the original image with "-over" appended to the end of the filename. */
以上是关于不引人注目的鼠标图像交换与预加载的主要内容,如果未能解决你的问题,请参考以下文章