JS实现图片高亮展示效果实例


Posted in Javascript onNovember 24, 2015

本文实例讲述了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 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://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="/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程序设计有所帮助。

Javascript 相关文章推荐
javascript显示隐藏层比较不错的方法分析
Sep 30 Javascript
IE6 hack for js 集锦
Sep 23 Javascript
JQuery插件jcarousellite的参数中文说明
May 11 Javascript
JS实现网页上随机产生超链接地址的方法
Nov 09 Javascript
Javascript简写条件语句(推荐)
Jun 12 Javascript
详解JavaScript树结构
Jan 09 Javascript
vue学习之mintui picker选择器实现省市二级联动示例
Oct 12 Javascript
关于Angularjs中跨域设置白名单问题
Apr 17 Javascript
Vue中props的使用详解
Jun 15 Javascript
vue src动态加载请求获取图片的方法
Oct 17 Javascript
微信小程序网络请求实现过程解析
Nov 06 Javascript
Vue使用Proxy代理后仍无法生效的解决
Nov 13 Javascript
JS截取字符串实例详解
Nov 24 #Javascript
超漂亮的jQuery图片轮播特效
Nov 24 #Javascript
jquery实现移动端点击图片查看大图特效
Sep 11 #Javascript
jquery解析json格式数据的方法(对象、字符串)
Nov 24 #Javascript
Bootstrap每天必学之按钮(一)
Nov 24 #Javascript
JavaScript DOM 学习总结(五)
Nov 24 #Javascript
jQuery解析json数据实例分析
Nov 24 #Javascript
You might like
php strlen mb_strlen计算中英文混排字符串长度
2009/07/10 PHP
改进UCHOME的记录发布,增强可访问性用户体验
2011/01/17 Javascript
JavaScript面向对象设计二 构造函数模式
2011/12/20 Javascript
EXTjs4.0的store的findRecord的BUG演示代码
2013/06/08 Javascript
js如何实现设计模式中的模板方法
2013/07/23 Javascript
js中arguments的用法(实例讲解)
2013/11/30 Javascript
JavaScript中数据结构与算法(五):经典KMP算法
2015/06/19 Javascript
基于jquery实现导航菜单高亮显示(两种方法)
2015/08/23 Javascript
JS实现网页上随滚动条滚动的层效果代码
2015/11/04 Javascript
Javascript页面跳转常见实现方式汇总
2015/11/28 Javascript
详解jQuery Mobile自定义标签
2016/01/06 Javascript
jQuery常用的一些技巧汇总
2016/03/26 Javascript
Bootstrap组件(一)之菜单
2016/05/11 Javascript
基于Bootstrap的UI扩展 StyleBootstrap
2016/06/17 Javascript
微信小程序 Record API详解及实例代码
2016/09/30 Javascript
angularjs封装$http为factory的方法
2017/05/18 Javascript
Vue.js实现图片的随意拖动方法
2018/03/08 Javascript
javascript实现倒计时效果
2020/02/17 Javascript
手把手带你入门微信小程序新框架Kbone的使用
2020/02/25 Javascript
python读取oracle函数返回值
2016/07/18 Python
Python 高级专用类方法的实例详解
2017/09/11 Python
python 读取竖线分隔符的文本方法
2018/12/20 Python
NumPy统计函数的实现方法
2020/01/21 Python
html5 标签
2009/07/16 HTML / CSS
外企求职信范文分享
2013/12/31 职场文书
经典大学生求职信范文
2014/01/06 职场文书
股东合作协议书
2014/04/14 职场文书
推广活动策划方案
2014/08/23 职场文书
房屋出租委托书格式
2014/09/23 职场文书
县长群众路线对照检查材料思想汇报
2014/10/02 职场文书
导游词开场白
2015/01/31 职场文书
宝宝满月宴答谢词
2015/09/30 职场文书
Python实现简繁体转换
2021/06/07 Python
MySQL的InnoDB存储引擎的数据页结构详解
2022/03/03 MySQL
Meta增速拉垮,元宇宙难当重任
2022/04/29 数码科技
Spring boot实现上传文件到本地服务器
2022/08/14 Java/Android