本文實例講述了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程式設計有所幫助。

C 和JavaScript通過WebAssembly實現互操作性。 1)C 代碼編譯成WebAssembly模塊,引入到JavaScript環境中,增強計算能力。 2)在遊戲開發中,C 處理物理引擎和圖形渲染,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靈活,廣泛用於前端和服務器端編程。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

ZendStudio 13.5.1 Mac
強大的PHP整合開發環境

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3 Linux新版
SublimeText3 Linux最新版