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 获取Mouse Position(鼠标坐标)的代码
Sep 21 Javascript
打印json对象的内容及JSON.stringify函数应用
Mar 29 Javascript
javascript中的toFixed固定小数位数 简单实例分享
Jul 12 Javascript
JS实现闪动的title消息提醒效果
Jun 20 Javascript
原生JavaScript实现合并多个数组示例
Sep 21 Javascript
微信小程序(三):网络请求
Jan 13 Javascript
jQuery实现字符串全部替换的方法【推荐】
Mar 09 Javascript
vue项目打包部署_nginx代理访问方法详解
Sep 20 Javascript
详解JavaScript函数callee、call、apply的区别
Mar 08 Javascript
js实现继承的方法及优缺点总结
May 08 Javascript
JS使用正则表达式判断输入框失去焦点事件
Oct 16 Javascript
vue项目中微信登录的实现操作
Sep 08 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 广告调用类代码(支持Flash调用)
2011/08/11 PHP
PHP设计模式之迭代器模式的深入解析
2013/06/13 PHP
Laravel实现构造函数自动依赖注入的方法
2016/03/16 PHP
基于PHP实现用户注册登录功能
2016/10/14 PHP
Laravel框架Eloquent ORM删除数据操作示例
2019/12/03 PHP
jquery插件 autoComboBox 下拉框
2010/12/22 Javascript
JavaScript在XHTML中的用法详解
2013/04/11 Javascript
jquery实现加载等待效果示例
2013/09/25 Javascript
js showModalDialog 弹出对话框的简单实例(子窗体)
2014/01/07 Javascript
jQuery的live()方法对hover事件的处理示例
2014/02/27 Javascript
使用jQuery设置disabled属性与移除disabled属性
2014/08/21 Javascript
javascript实现表格增删改操作实例详解
2015/05/15 Javascript
javascript多物体运动实现方法分析
2016/01/08 Javascript
jQuery CSS3相结合实现时钟插件
2016/01/08 Javascript
JS获取和修改元素样式的实例代码
2016/08/06 Javascript
微信小程序实战之运维小项目
2017/01/17 Javascript
jQuery幻灯片插件owlcarousel参数说明中文文档
2018/02/27 jQuery
Redux实现组合计数器的示例代码
2018/07/04 Javascript
微信小程序实现红包雨功能
2018/07/11 Javascript
详解ESLint在Vue中的使用小结
2018/10/15 Javascript
Vue防止白屏添加首屏动画的实例
2019/10/31 Javascript
python 通过SSHTunnelForwarder隧道连接redis的方法
2019/02/19 Python
Python、 Pycharm、Django安装详细教程(图文)
2019/04/12 Python
python实现海螺图片的方法示例
2019/05/12 Python
Python 在局部变量域中执行代码
2020/08/07 Python
戴尔荷兰官方网站:Dell荷兰
2020/10/04 全球购物
业务经理岗位职责
2013/11/11 职场文书
中英文自我评价常用句型
2013/12/19 职场文书
校长就职演讲稿
2014/01/06 职场文书
网络程序员自荐信
2014/01/25 职场文书
合作经营协议书
2014/04/17 职场文书
一分钟演讲稿
2014/04/30 职场文书
党员个人对照检查材料思想汇报
2014/09/16 职场文书
2014物价局群众路线对照检查材料思想汇报
2014/09/21 职场文书
升职自我推荐信范文
2015/03/25 职场文书
MySQL的存储函数与存储过程的区别解析
2022/04/08 MySQL