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 相关文章推荐
将HTMLCollection/NodeList/伪数组转换成数组的实现方法
Jun 20 Javascript
Extjs gridpanel 出现横向滚动条问题的解决方法
Jul 04 Javascript
JQuery入门—编写一个简单的JQuery应用案例
Jan 03 Javascript
JQuery+DIV自定义滚动条样式的具体实现
Jun 25 Javascript
JavaScript实现数字数组正序排列的方法
Apr 06 Javascript
js获取html的span标签的值方法(超简单)
Jul 26 Javascript
小程序开发实战:实现九宫格界面的导航的代码实现
Jan 19 Javascript
微信小程序 基础知识css样式media标签
Feb 15 Javascript
Node.js连接Sql Server 2008及数据层封装详解
Aug 27 Javascript
基于jquery实现九宫格拼图小游戏
Nov 30 jQuery
JavaScript实现的鼠标跟随特效示例【2则实例】
Dec 22 Javascript
只有 20 行的 JavaScript 模板引擎实例详解
May 11 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
PHP5全版本绕过open_basedir读文件脚本漏洞详细介绍
2015/01/20 PHP
CodeIgniter多语言实现方法详解
2016/01/20 PHP
程序员的表白神器“520”大声喊出来
2016/05/20 PHP
php实现mysql连接池效果实现代码
2018/01/25 PHP
PHP时间类完整代码实例
2021/02/26 PHP
做网页的一些技巧
2007/02/01 Javascript
javascript网页关键字高亮代码
2008/07/30 Javascript
FireFox JavaScript全局Event对象
2009/06/14 Javascript
ExtJS GTGrid 简单用户管理
2009/07/01 Javascript
javascript笔记 String类replace函数的一些事
2011/09/22 Javascript
javascript中apply和call方法的作用及区别说明
2014/02/14 Javascript
AngularJS使用指令增强标准表单元素功能
2016/07/01 Javascript
JQuery实现DIV其他动画效果的简单实例
2016/09/18 Javascript
Vue使用vue-cli创建项目
2017/09/01 Javascript
jQuery NProgress.js加载进度插件的简单使用方法
2018/01/31 jQuery
JavaScript 五大常见函数
2018/03/23 Javascript
Angular angular-file-upload文件上传的示例代码
2018/08/23 Javascript
详解@angular/cli 改变默认启动端口两种方式
2018/11/29 Javascript
JS判断浏览器类型与操作系统的方法分析
2020/04/30 Javascript
Python脚本实现集群检测和管理功能
2015/03/06 Python
PHP实现发送和接收JSON请求
2018/06/07 Python
Python openpyxl 插入折线图实例
2020/04/17 Python
Python3+Appium安装及Appium模拟微信登录方法详解
2021/02/16 Python
工商企业管理实习自我鉴定
2013/12/04 职场文书
行政部总经理岗位职责
2014/01/04 职场文书
工程安全员岗位职责
2014/03/09 职场文书
交通事故调解协议书
2014/04/16 职场文书
小区的门卫岗位职责
2014/10/01 职场文书
廉洁自律承诺书范文
2015/04/28 职场文书
个人催款函范文
2015/06/23 职场文书
爱国主义教育主题班会
2015/08/13 职场文书
python中的None与NULL用法说明
2021/05/25 Python
Nginx反向代理学习实例教程
2021/10/24 Servers
mysql下的max_allowed_packet参数设置详解
2022/02/12 MySQL
css filter和getUserMedia的联合使用
2022/02/24 HTML / CSS
PostgreSQL怎么创建分区表详解
2022/06/25 PostgreSQL