jquery实现背景墙聚光灯效果示例分享


Posted in Javascript onMarch 02, 2014
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
 "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
 <meta http-equiv="Content-type" content="text/html; charset=utf-8">
 <title>jQuery背景墙聚光灯效果代码 </title>
 <script type="text/javascript" charset="utf-8" src='/jquery.js'></script>
 <script type="text/javascript" charset="utf-8">
  $(window).load(function(){
   var spotlight = {
     // the opacity of the "transparent" images - change it if you like
    opacity : 0.2,
    /*the vars bellow are for width and height of the images so we can make 
    the <li> same size */
    imgWidth : $('.spotlightWrapper ul li').find('img').width(), 
    imgHeight : $('.spotlightWrapper ul li').find('img').height() 
   };
   //set the width and height of the list items same as the images
   $('.spotlightWrapper ul li').css({ 'width' : spotlight.imgWidth, 'height' : spotlight.imgHeight });
   //when mouse over the list item...
   $('.spotlightWrapper ul li').hover(function(){
    //...find the image inside of it and add active class to it and change opacity to 1 (no transparency)
    $(this).find('img').addClass('active').css({ 'opacity' : 1});
    //get the other list items and change the opacity of the images inside it to the one we have set in the spotlight array 
    $(this).siblings('li').find('img').css({'opacity' : spotlight.opacity}) ;
    //when mouse leave...
   }, function(){
    //... find the image inside of the list item we just left and remove the active class
    $(this).find('img').removeClass('active');
   });
   //when mouse leaves the unordered list...
   $('.spotlightWrapper ul').bind('mouseleave',function(){
    //find the images and change the opacity to 1 (fully visible)
    $(this).find('img').css('opacity', 1);
   });
  });
 </script>
 <style type="text/css" media="screen">
  body { background:black; color:white; font-family: 'georgia' } /* not important */
  .spotlightWrapper ul { 
   list-style-type: none; /* remove the default style for list items (the circles) */ 
   margin:0px; /* remove default margin */
   padding:0px; /* remove default padding */
  }
  .spotlightWrapper ul li { 
   float:left; /* important: left float */
   position:relative; /* so we can use top and left positioning */
  }
  .spotlightWrapper ul li a img { 
   width:200px; /* you don't need this, i just rescaled the images they are bigger then i want them to be ' */
   position:relative; /* so we can use top and left positioning */
   border:none; /* remove the default blue border */
  }
  .spotlightWrapper ul li a img.active {
   border:4px solid white; /* choose whatever you like */
   z-index:1; /* show it on top of the other images (they have z-index 0) */
   left: -4px; /* same as border width but negative */
   top: -4px; /* same as border width but negative */
  }
  .clear { clear:both; } /* to clear the float after the last item */
 </style>
</head>
<body>
 <h3>jQuery背景墙聚光灯效果</h3>
    <p>点击图片查看效果</p>
 <!-- start spotlightWrapper div -->
<div class='spotlightWrapper'>
  <!-- start unordered list -->
  <ul>
   <li><a href='#'><img src='images/1.jpg' /></a></li>
   <li><a href='#'><img src='images/2.jpg' /></a></li>
   <li><a href='#'><img src='images/3.png' /></a></li>
   <li><a href='#'><img src='images/4.jpg' /></a></li>
   <li><a href='#'><img src='images/5.jpg' /></a></li>
   <li><a href='#'><img src='images/6.png' /></a></li>
   <li><a href='#'><img src='images/7.jpg' /></a></li>
   <li><a href='#'><img src='images/9.PNG' /></a></li>
   <li><a href='#'><img src='images/10.jpg' /></a></li>
   <li><a href='#'><img src='images/11.png' /></a></li>
   <li><a href='#'><img src='images/12.png' /></a></li>
   <li><a href='#'><img src='images/13.jpg' /></a></li>
   <li><a href='#'><img src='images/14.png' /></a></li>
   <li><a href='#'><img src='images/15.jpg' /></a></li>
   <li><a href='#'><img src='images/16.jpg' /></a></li>
   <div class='clear'></div>
  </ul>
  <!-- end unordered list -->
 </div>
 <!-- end spolightWrapper div -->
</body>
</html>
Javascript 相关文章推荐
JS支持带x身份证号码验证函数
Aug 10 Javascript
jQuery AJAX 调用WebService实现代码
Mar 24 Javascript
jQuery实现选项联动轮播效果【附实例】
Apr 19 Javascript
JavaScript中获取HTML元素值的三种方法
Jun 20 Javascript
表单元素值获取方式js及java方式的简单实例
Oct 15 Javascript
js学习之----深入理解闭包
Nov 21 Javascript
node.js实现回调的方法示例
Mar 01 Javascript
javascript数组拍平方法总结
Jan 20 Javascript
微信小程序按钮点击跳转页面详解
May 06 Javascript
Element-UI中关于table表格的那些骚操作(小结)
Aug 15 Javascript
vue实现鼠标经过动画
Oct 16 Javascript
VUE渲染后端返回含有script标签的html字符串示例
Oct 28 Javascript
jquery制作弹窗提示窗口代码分享
Mar 02 #Javascript
jquery中ajax函数执行顺序问题之如何设置同步
Feb 28 #Javascript
JavaScript获取当前页面上的指定对象示例代码
Feb 28 #Javascript
jquery获取当前点击对象的value方法
Feb 28 #Javascript
经过绑定元素时会多次触发mouseover和mouseout事件
Feb 28 #Javascript
判断某个字符在一个字符串中是否存在的js代码
Feb 28 #Javascript
如何设置一定时间内只能发送一次请求
Feb 28 #Javascript
You might like
通用PHP动态生成静态HTML网页的代码
2010/03/04 PHP
Convert Seconds To Hours
2007/06/16 Javascript
理解Javascript_01_理解内存分配原理分析
2010/10/11 Javascript
Javascript自定义函数判断网站访问类型是PC还是移动终端
2014/01/10 Javascript
javascript制作2048游戏
2015/03/30 Javascript
自己编写的支持Ajax验证的JS表单验证插件
2015/05/15 Javascript
javascript常用的方法分享
2015/07/01 Javascript
jQuery实现带滑动条的菜单效果代码
2015/08/26 Javascript
jQuery-1.9.1源码分析系列(十)事件系统之事件体系结构
2015/11/19 Javascript
jQuery基于BootStrap样式实现无限极地区联动
2016/08/26 Javascript
Angularjs实现mvvm式的选项卡示例代码
2016/09/08 Javascript
js中开关变量使用实例
2017/02/24 Javascript
angularjs实现下拉列表的选中事件示例
2017/03/03 Javascript
动态统计当前输入内容的字节、字符数的实例详解
2017/10/27 Javascript
vue获取元素宽、高、距离左边距离,右,上距离等还有XY坐标轴的方法
2018/09/05 Javascript
jquery将信息遍历到界面上实例代码
2020/01/21 jQuery
Vue的状态管理vuex使用方法详解
2020/02/05 Javascript
jquery实现有过渡效果的tab切换
2020/07/17 jQuery
[06:15]2016国际邀请赛中国区预选赛单车采访:我顶WINGS
2016/06/27 DOTA
Swift中的协议(protocol)学习教程
2016/07/08 Python
Django 静态文件配置过程详解
2019/07/23 Python
python读取csv文件指定行的2种方法详解
2020/02/13 Python
Python多进程multiprocessing、进程池用法实例分析
2020/03/24 Python
Anaconda配置pytorch-gpu虚拟环境的图文教程
2020/04/16 Python
奥地利汽车配件店:Pkwteile.at
2017/03/10 全球购物
美国市场上最实惠的送餐服务:Dinnerly
2018/03/18 全球购物
Otticanet澳大利亚:最顶尖的世界名牌眼镜, 能得到打折季的价格
2018/08/23 全球购物
Interrail法国:乘火车探索欧洲,最受欢迎的欧洲铁路通票
2019/08/27 全球购物
.NET里面什么时候需要调用垃圾回收
2015/06/01 面试题
求职简历中个人的自我评价
2013/12/01 职场文书
《我爱祖国》演讲稿1000字
2014/09/26 职场文书
建筑工程挂靠协议书
2016/03/23 职场文书
Nginx下配置Https证书详细过程
2021/04/01 Servers
利用Python+OpenCV三步去除水印
2021/05/28 Python
关于Numpy之repeat、tile的用法总结
2021/06/02 Python
详细了解java监听器和过滤器
2021/07/09 Java/Android