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 连接数据库如何操作数据库中的数据
Nov 23 Javascript
原生JavaScript实现连连看游戏(附源码)
Nov 05 Javascript
JS正则验证邮箱的格式详细介绍
Nov 19 Javascript
iframe里面的元素触发父窗口元素事件的jquery代码
Oct 19 Javascript
jQuery中on()方法用法实例
Jan 19 Javascript
jQuery往textarea中光标所在位置插入文本的方法
Jun 26 Javascript
JavaScript实现点击自动选择TextArea文本的方法
Jul 02 Javascript
Vue.js基础指令实例讲解(各种数据绑定、表单渲染大总结)
Jul 03 Javascript
for循环 + setTimeout 结合一些示例(前端面试题)
Aug 30 Javascript
解决axios会发送两次请求,有个OPTIONS请求的问题
Oct 25 Javascript
支付宝小程序自定义弹窗dialog插件的实现代码
Nov 30 Javascript
详解django模板与vue.js冲突问题
Jul 07 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查询MySQL大量数据的时候内存占用分析
2011/07/22 PHP
解析smarty模板中类似for的功能实现
2013/06/18 PHP
基于PHP的简单采集数据入库程序【续篇】
2014/07/30 PHP
PHP读取文本文件并逐行输出该行使用最多的字符与对应次数的方法
2016/11/25 PHP
PHP API接口必备之输出json格式数据示例代码
2017/06/27 PHP
JQuery困惑—包装集 DOM节点
2009/10/16 Javascript
jquery绑定原理 简单解析与实现代码分享
2011/09/06 Javascript
一样的table?不一样的table(可编辑状态table)
2012/09/19 Javascript
复制js对象方法(详解)
2013/07/08 Javascript
jquery.form.js用法之清空form的方法
2014/03/07 Javascript
用box固定长宽实现图片自动轮播js代码
2014/06/09 Javascript
localResizeIMG先压缩后使用ajax无刷新上传(移动端)
2015/08/11 Javascript
关于JavaScript和jQuery的类型判断详解
2016/10/08 Javascript
Angular实现的table表格排序功能完整示例
2017/12/22 Javascript
基于vue2的canvas时钟倒计时组件步骤解析
2018/11/05 Javascript
vue-quill-editor的使用及个性化定制操作
2020/08/04 Javascript
独特的python循环语句
2016/11/20 Python
python构建深度神经网络(DNN)
2018/03/10 Python
python求解数组中两个字符串的最小距离
2018/09/27 Python
详解python中递归函数
2019/04/16 Python
Flask框架路由和视图用法实例分析
2019/11/07 Python
python反转列表的三种方式解析
2019/11/08 Python
python利用os模块编写文件复制功能——copy()函数用法
2020/07/13 Python
可以使用抽象函数重写基类中的虚函数吗
2013/06/02 面试题
Java语言程序设计测试题判断题部分
2013/01/06 面试题
医院护士求职自荐信格式
2013/09/21 职场文书
思想品德自我评价
2014/02/04 职场文书
公司中秋节活动方案
2014/02/12 职场文书
大学生怎样写好自荐信
2014/02/25 职场文书
《陋室铭》教学反思
2014/02/26 职场文书
夫妻分居协议书范本(有子女版)
2014/11/01 职场文书
大学生实训报告总结
2014/11/05 职场文书
不同意离婚上诉状
2015/05/23 职场文书
为什么node.js不适合大型项目
2021/04/28 Javascript
业余无线电通联Q语
2022/02/18 无线电
MySQL提升大量数据查询效率的优化神器
2022/07/07 MySQL