本文实例讲述了JS实现图片高亮展示效果的方法。分享给大家供大家参考,具体如下:
昨天朋友让我帮着做个图片高亮展示的效果,虽然不难,不过满有创意的:
<!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>name</title> <style type="text/css"> *{}{margin:0; padding:0;} a img{}{border:none;} #imagesBox {}{ width:165px; height:110px; position:relative; left:100px; top:100px; z-index:1; border:1px solid black; background-color:white;} #trans{}{ width:165px; height:110px; position:absolute; left:0; top: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; top:50%; margin-top:-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 src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" alt="名称1"/><span></span></a></li> <li><a href="#" title="名称2"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" alt="名称2"/><span></span></a></li> <li><a href="#" title="名称3"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" alt="名称3"/><span></span></a></li> <li><a href="#" title="名称4"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" alt="名称4"/><span></span></a></li> <li><a href="#" title="名称5"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" alt="名称5"/><span></span></a></li> <li><a href="#" title="名称6"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" onmouseover="gallery(this);" onmouseout="clearBg(this)" style="max-width:90%" style="max-width:90%" 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://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>name</title> <style type="text/css"> *{margin:0; padding:0;} a img{border:none;} #imagesBox { width:165px; height:100px; position:relative; left:100px; top: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; top: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; top:50%; margin-top:-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="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称1"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称2"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称2"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称3"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称3"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称4"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称4"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称5"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称5"/><span></span></a></li> <li><a href="#" onmouseover="gallery(this);" title="名称6"><img src="/static/imghwm/default1.png" data-src="/images/artist//12053006018793_3.jpg" class="lazy" style="max-width:90%" style="max-width:90%" alt="名称6"/><span></span></a></li> </ul> <strong id="show_tit">这里显示名字</strong> </div> </body> </html>
希望本文所述对大家JavaScript程序设计有所帮助。

JavaScript在网站、移动应用、桌面应用和服务器端编程中均有广泛应用。1)在网站开发中,JavaScript与HTML、CSS一起操作DOM,实现动态效果,并支持如jQuery、React等框架。2)通过ReactNative和Ionic,JavaScript用于开发跨平台移动应用。3)Electron框架使JavaScript能构建桌面应用。4)Node.js让JavaScript在服务器端运行,支持高并发请求。

Python更适合数据科学和自动化,JavaScript更适合前端和全栈开发。1.Python在数据科学和机器学习中表现出色,使用NumPy、Pandas等库进行数据处理和建模。2.Python在自动化和脚本编写方面简洁高效。3.JavaScript在前端开发中不可或缺,用于构建动态网页和单页面应用。4.JavaScript通过Node.js在后端开发中发挥作用,支持全栈开发。

C和C 在JavaScript引擎中扮演了至关重要的角色,主要用于实现解释器和JIT编译器。 1)C 用于解析JavaScript源码并生成抽象语法树。 2)C 负责生成和执行字节码。 3)C 实现JIT编译器,在运行时优化和编译热点代码,显着提高JavaScript的执行效率。

JavaScript在现实世界中的应用包括前端和后端开发。1)通过构建TODO列表应用展示前端应用,涉及DOM操作和事件处理。2)通过Node.js和Express构建RESTfulAPI展示后端应用。

JavaScript在Web开发中的主要用途包括客户端交互、表单验证和异步通信。1)通过DOM操作实现动态内容更新和用户交互;2)在用户提交数据前进行客户端验证,提高用户体验;3)通过AJAX技术实现与服务器的无刷新通信。

理解JavaScript引擎内部工作原理对开发者重要,因为它能帮助编写更高效的代码并理解性能瓶颈和优化策略。1)引擎的工作流程包括解析、编译和执行三个阶段;2)执行过程中,引擎会进行动态优化,如内联缓存和隐藏类;3)最佳实践包括避免全局变量、优化循环、使用const和let,以及避免过度使用闭包。

Python更适合初学者,学习曲线平缓,语法简洁;JavaScript适合前端开发,学习曲线较陡,语法灵活。1.Python语法直观,适用于数据科学和后端开发。2.JavaScript灵活,广泛用于前端和服务器端编程。

Python和JavaScript在社区、库和资源方面的对比各有优劣。1)Python社区友好,适合初学者,但前端开发资源不如JavaScript丰富。2)Python在数据科学和机器学习库方面强大,JavaScript则在前端开发库和框架上更胜一筹。3)两者的学习资源都丰富,但Python适合从官方文档开始,JavaScript则以MDNWebDocs为佳。选择应基于项目需求和个人兴趣。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

Atom编辑器mac版下载
最流行的的开源编辑器

SublimeText3 Linux新版
SublimeText3 Linux最新版

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

禅工作室 13.0.1
功能强大的PHP集成开发环境

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。