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函数库)S.Sams Lifexperience ScriptClassLib
Apr 29 Javascript
Javascript面向对象编程
Mar 18 Javascript
JQuery学习笔录 简单的JQuery
Apr 09 Javascript
全面解析Bootstrap表单样式的使用
Sep 09 Javascript
jQuery实现的模拟弹出窗口功能示例
Nov 24 Javascript
Node.js使用Express创建Web项目详细教程
Mar 31 Javascript
React Native预设占位placeholder的使用
Sep 28 Javascript
深入理解js 中async 函数的含义和用法
May 13 Javascript
layui 中select下拉change事件失效的解决方法
Sep 20 Javascript
解决layer 关闭当前弹窗 关闭遮罩层 input值获取不到的问题
Sep 25 Javascript
vue实现自定义多选按钮
Jul 16 Javascript
vue-cli3.x配置全局的scss的时候报错问题及解决
Apr 30 Vue.js
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显示搜索引擎来的关键词
2014/02/13 PHP
PHP调用其他文件中的类
2018/04/02 PHP
php判断电子邮件是否正确方法
2018/12/04 PHP
php实现网页上一页下一页翻页过程详解
2019/06/28 PHP
Javascript &amp; DHTML 实例编程(教程)DOM基础和基本API
2007/06/02 Javascript
javascript 读取图片文件的大小
2009/06/25 Javascript
Node.js(安装,启动,测试)
2014/06/09 Javascript
分享一则javascript 调试技巧
2015/01/02 Javascript
JS中使用apply方法通过不同数量的参数调用函数的方法
2016/05/31 Javascript
JS 日期与时间戮相互转化的简单实例
2016/06/22 Javascript
JS监听微信、支付宝等移动app及浏览器的返回、后退、上一页按钮的事件方法
2016/08/05 Javascript
AngularJs 利用百度地图API 定位当前位置 获取地址信息
2017/01/18 Javascript
轻松理解JavaScript之AJAX
2017/03/15 Javascript
jQuery is not defined 错误原因与解决方法小结
2017/03/19 Javascript
angular.fromJson与toJson方法用法示例
2017/05/17 Javascript
Vue props用法详解(小结)
2018/07/03 Javascript
webpack的CSS加载器的使用
2018/09/11 Javascript
JS计算两个数组的交集、差集、并集、补集(多种实现方式)
2019/05/21 Javascript
转换layUI的数据表格中的日期格式方法
2019/09/19 Javascript
在Angular中实现一个级联效果的下拉框的示例代码
2020/05/20 Javascript
python使用xmlrpc实例讲解
2013/12/17 Python
Python使用当前时间、随机数产生一个唯一数字的方法
2017/09/18 Python
Dlib+OpenCV深度学习人脸识别的方法示例
2019/05/14 Python
python定位xpath 节点位置的方法
2019/08/27 Python
python实现贪吃蛇游戏源码
2020/03/21 Python
5 个强大的HTML5 API 函数推荐
2014/11/19 HTML / CSS
美国最大的船只买卖在线市场:Boat Trader
2018/08/04 全球购物
澳大利亚领先的折扣药房:Chemist Direct(有中文站)
2018/11/24 全球购物
绢花、人造花和人造花卉:BLOOM
2019/08/07 全球购物
CK澳大利亚官网:Calvin Klein澳大利亚
2020/12/12 全球购物
函授毕业生自我鉴定
2013/11/06 职场文书
自我推荐书
2013/12/04 职场文书
2014年五四青年节演讲稿范文
2014/04/22 职场文书
广场舞大赛策划方案
2014/05/31 职场文书
党员个人总结范文
2015/02/14 职场文书
小学教师工作总结2015
2015/04/07 职场文书