当用户的鼠标经过小图时,旁边放大显示大图效果,移开后图层自动隐藏,实用的图片放大显示特效。
<!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> <meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren"> <meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。"> <style type="text/css"> html,body{overflow:hidden;} body,div,ul,li{margin:0;padding:0;} #box_www_wuming_ren ul{width:768px;height:172px;list-style-type:none;margin:10px auto;} #box_www_wuming_ren li{float:left;width:170px;height:170px;cursor:pointer;display:inline;border:1px solid #ddd;margin:0 10px;} #box_www_wuming_ren li.active{border:1px solid #a10000;} #box_www_wuming_ren li img{width:170px;height:170px;vertical-align:top;} #big_www_wuming_ren{position:absolute;width:400px;height:400px;border:2px solid #ddd;display:none;} #big_www_wuming_ren div{position:absolute;top:0;left:0;width:400px;height:400px;opacity:0.5;filter:alpha(opacity=50);background:#fff url(/img/20240223_www_wuming_ren_6.gif) 50% 50% no-repeat;} </style> <script type="text/javascript"> window.onload = function () {//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) var aLi = document.getElementsByTagName("li"); var oBig = document.getElementById("big_www_wuming_ren"); var oLoading = oBig.getElementsByTagName("div")[0]; var i = 0; for (i = 0; i < aLi.length; i++) { aLi[i].index = i; //鼠标划过, 预加载图片插入容器并显示 aLi[i].onmouseover = function () { var oImg = document.createElement("img"); //图片预加载 var img = new Image(); img.src = oImg.src = aLi[this.index].getElementsByTagName("img")[0].src.replace(".jpg","_wuming.jpg"); //插入大图片 oBig.appendChild(oImg); //鼠标移过样式 this.className = "active"; //显示big oBig.style.display = oLoading.style.display = "block"; //判断大图是否加载成功 img.complete ? oLoading.style.display = "none" : (oImg.onload = function() {oLoading.style.display = "none";}) }; //鼠标移动, 大图容器跟随鼠标移动 aLi[i].onmousemove = function (event) { var event = event || window.event; var iWidth = document.documentElement.offsetWidth - event.clientX; //设置big的top值 oBig.style.top = event.clientY + 20 + "px"; //设置big的left值, 如果右侧显示区域不够, 大图将在鼠标左侧显示. oBig.style.left = (iWidth < oBig.offsetWidth + 10 ? event.clientX - oBig.offsetWidth - 10 : event.clientX + 10) + "px"; }; //鼠标离开, 删除大图并隐藏大图容器 aLi[i].onmouseout = function () { this.className = ""; oBig.style.display = "none"; //移除大图片 oBig.removeChild(oBig.lastChild) } } };//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) </script> </head> <body> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> <div id="box_www_wuming_ren"> <ul> <li><img src="/img/20240223_wuming_ren_1.jpg" /></li> <li><img src="/img/20240223_wuming_ren_2.jpg" /></li> <li><img src="/img/20240223_wuming_ren_3.jpg" /></li> <li><img src="/img/20240223_wuming_ren_4.jpg" /></li> </ul> </div> <div id="big_www_wuming_ren"><div></div></div> </body> </html>
本文来自武鸣人网站,转载请注明出处