SoFunction
Updated on 2025-02-28

JS implementation example of image highlighting effect

This article describes the method of JS to achieve image highlighting effect. Share it for your reference, as follows:

Yesterday, my friend asked me to help with the highlighting effect of the picture. Although it is not difficult, it is very creative:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http:///TR/xhtml1/DTD/">
<html xmlns="http:///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=("alt");  
    ("show_tit").=tit;
    ("trans").='block';
    ="3";
  }
  function clearBg(obj){
    ("show_tit").="";
    ("trans").='none';
    ="1";
  }
</script>
</head>
<body>
<div > 
  <ul>
  &lt;li&gt;&lt;a href="#" title="name1"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name1"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" title="name 2"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name 2"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" title="name3"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name3"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" title="name 4"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name 4"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" title="name5"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name5"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" title="name 6"><img onmouseover="gallery(this);" onmouseout="clearBg(this)" src="/images/artist//12053006018793_3.jpg" height="55" width="55" alt="name 6"/><span></span></a></li> &lt;/ul&gt;
&lt;div &gt;&amp;nbsp;&lt;/div&gt;
&lt;strong &gt;&amp;nbsp;&lt;/strong&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

At the beginning, because I didn't fully understand the design intention, I accidentally made this effect:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http:///TR/xhtml1/DTD/"&gt;
&lt;html xmlns="http:///1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;name&lt;/title&gt;
&lt;style type="text/css"&gt;
*{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;} 
&lt;/style&gt;
&lt;script type="text/javascript"&gt;
  function gallery(obj){
    var tit=("title");  
    ("show_tit").=tit;
    ("imagesBox").onmouseout=function(){("show_tit").="Showed here
 name"};
  }
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div &gt;
 &lt;ul&gt;
  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name1"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 1"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name2"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 2"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name3"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 3"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name 4"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 4"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name5"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 5"/><span></span></a></li>  &lt;li&gt;&lt;a href="#" onmouseover="gallery(this);" title="name6"><img src="/images/artist//12053006018793_3.jpg" height="55"width="55" alt="name 6"/><span></span></a></li> &lt;/ul&gt;
 &lt;strong &gt;Show the name here&lt;/strong&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

I hope this article will be helpful to everyone's JavaScript programming.