JS实现图片高亮展示效果实例
网络编程 2021-07-04 21:03www.168986.cn编程入门
这篇文章主要介绍了JS实现图片高亮展示效果的方法,实例分析了JavaScript响应鼠标事件动态操作页面元素样式的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了JS实现图片高亮展示效果的方法。分享给大家供大家参考,具体如下
昨天朋友让我帮着做个图片高亮展示的效果,虽然不难,不过满有创意的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>name</title> <style type="text/css"> {}{margin:0; padding:0;} a img{}{border:none;} #imagesBox {}{ width:165px; height:110px; position:relative; left:100px; :100px; z-index:1; border:1px solid black; background-color:white;} #trans{}{ width:165px; height:110px; position:absolute; left:0; :0; z-index:2; display:none; opacity:0.5; filter:alpha(opacity=50); background-color:black;} #imagesBox li {}{ width:55px; height:55px; float:left; overflow:hidden;} #imagesBox li a,#imagesBox li img {}{ width:55px; height:55px; display:block; cursor:pointer;} #imagesBox li img{}{ position:relative;} #imagesBox strong{}{position:absolute;left:0; :50%; margin-:-7px; z-index:999; display:block; color:white; width:100%; height:15px; text-align:center; z-index:999;} </style> <script type="text/javascript"> function gallery(obj){ var tit=obj.getAttribute("alt"); document.getElementById("show_tit").firstChild.nodeValue=tit; document.getElementById("trans").style.display='block'; obj.style.zIndex="3"; } function clearBg(obj){ document.getElementById("show_tit").firstChild.nodeValue=""; document.getElementById("trans").style.display='none'; obj.style.zIndex="1"; } </script> </head> <body> <div id="imagesBox"> <ul> <li><a href="#" title="名称1"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称1"/><span></span></a></li> <li><a href="#" title="名称2"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称2"/><span></span></a></li> <li><a href="#" title="名称3"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称3"/><span></span></a></li> <li><a href="#" title="名称4"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称4"/><span></span></a></li> <li><a href="#" title="名称5"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称5"/><span></span></a></li> <li><a href="#" title="名称6"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称6"/><span></span></a></li> </ul> <div id="trans"> </div> <strong id="show_tit"> </strong> </div> </body> </html>
刚开始因为没有完全明白设计意图,阴差阳错的做了个这样的效果
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://.w3./1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>name</title> <style type="text/css"> {margin:0; padding:0;} a img{border:none;} #imagesBox { width:165px; height:100px; position:relative; left:100px; :100px;} #imagesBox li { width:55px; height:55px; float:left; overflow:hidden; position:relative;} #imagesBox li img { width:55px; height:55px; position:relative; z-index:2; } #imagesBox li span { line-height:100px; background:#000; position:absolute; :0; left:0; z-index:3; opacity:0.5; filter:alpha(opacity=50); display:block; width:55px; height:55px;} #imagesBox li a:hover span{display:none;} #imagesBox strong{position:absolute;left:0; :50%; margin-:-7px; z-index:999; display:block; color:white; width:100%; height:15px; text- align:center;} </style> <script type="text/javascript"> function gallery(obj){ var tit=obj.getAttribute("title"); document.getElementById("show_tit").firstChild.nodeValue=tit; document.getElementById("imagesBox").onmouseout=function(){document.getElementById("show_tit").firstChild.nodeValue="这里显示 名字"}; } </script> </head> <body> <div id="imagesBox"> <ul> <li><a href="#" onmouseover="gallery(this);" title="名称1"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称1"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称2"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称2"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称3"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称3"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称4"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称4"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称5"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称5"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称6"><img src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="名称6"/><span></span></a></li> </ul> <strong id="show_tit">这里显示名字</strong> </div> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程