zoukankan      html  css  js  c++  java
  • 京东首页图片轮换

      1 <%@ page language="java" contentType="text/html; charset=UTF-8"
      2     pageEncoding="UTF-8"%>
      3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      4 <html>
      5 <head>
      6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      7 <title>Insert title here</title>
      8 <style type="text/css">   
      9 *{margin:0;padding:0;list-style-type:none;}   
     10 body{font:12px/180% Arial, Helvetica, sans-serif, "宋体";color:#333;background:#f0f0f0;}   
     11 a,img{border:0;}   
     12 /* demo */   
     13 .demo{780px;margin:0 auto;}   
     14 .demo h2{height:70px;line-height:50px;font-size:22px;font-weight:normal;font-family:"Microsoft YaHei",SimHei;text-align:center;}   
     15 /* focus */   
     16 #focus{position:relative;780px;height:420px;overflow:hidden;}   
     17 #focus ul{height:420px;position:absolute;}   
     18 #focus ul li{float:left;780px;height:420px;overflow:hidden;position:relative;background:#000;}   
     19 #focus ul li div{position:absolute;overflow:hidden;}   
     20 #focus .btnBg{position:absolute;780px;height:40px;left:0;bottom:0;background:#000;}   
     21 #focus .btn{position:absolute;height:30px;left:10px;bottom:4px;}   
     22 #focus .btn span{   
     23     float:left;display:inline-block;30px;height:30px;line-height:30px;text-align:center;font-size:16px;margin-right:10px;cursor:pointer;background:#716564;color:#ffffff;   
     24     border-radius:15px;   
     25     -moz-border-radius:15px;   
     26     -webkit-border-radius:15px;   
     27 }   
     28 #focus .btn span.on{background:#B91919;color:#ffffff;}   
     29 </style>   
     30   
     31 <script type="text/javascript" src=js/jquery-1.7.2.min.js></script>
     32 <script type="text/javascript" src=js/jquery.easyui.min.js></script>
     33 <script type="text/javascript">   
     34 $(function(){   
     35     var sWidth = $("#focus").width();   
     36     //获取焦点图的宽度   
     37     var len = $("#focus ul li").length;    
     38     //获取焦点图长度   
     39     var index = 0;   
     40     //获取焦点图个数   
     41     var picTimer;   
     42     //创建一个picTimer参数   
     43   
     44     //以下代码添加数字按钮和按钮后的半透明长条   
     45     var btn = "<div class='btnBg'></div><div class='btn'>";   
     46     //将两个div和class都放进btn里面   
     47     for(var i=0; i < len; i++){   
     48     //然后一个判断   
     49         btn += "<span>" + (i+1) + "</span>";   
     50         //将判断放进btn里面进行判断   
     51     }   
     52     $("#focus").append(btn);   
     53     //显示下面的按钮很长条   
     54     $("#focus .btnBg").css("opacity",0.3);   
     55     //将下面的长条调整为半透明的   
     56   
     57     //为数字按钮添加鼠标滑入事件,以显示相应的内容   
     58     $("#focus .btn span").mouseenter(function(){   
     59     //改变背景颜色   
     60         index = $("#focus .btn span").index(this);   
     61         //定义鼠标触及按钮的事件   
     62         showPics(index);   
     63         //当显示那个图片相对应的按钮是按钮的背景颜色改变   
     64     }).eq(0).trigger("mouseenter");   
     65     //是一个选中的事件触及以后就自动选中就是按钮的触及效果   
     66   
     67        
     68     $("#focus ul").css("width",sWidth * (len + 1));   
     69     //本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度   
     70        
     71     $("#focus ul li div").hover(function(){   
     72         $(this).siblings().css("opacity",0.7);   
     73     },function() {   
     74         $("#focus ul li div").css("opacity",1);   
     75     });   
     76     //鼠标滑入某li中的某div里,调整其同辈div元素的透明度,由于li的背景为黑色,所以会有变暗的效果   
     77   
     78        
     79     $("#focus").hover(function(){   
     80         clearInterval(picTimer);   
     81         //鼠标滑上焦点图时停止自动播放,滑出时开始自动播放   
     82     },function(){   
     83         picTimer = setInterval(function(){   
     84             if(index == len){    
     85                 showFirPic();   
     86                 index = 0;   
     87         //如果索引值等于li元素个数,说明最后一张图播放完毕,接下来要显示第一张图,即调用showFirPic(),然后将索引值清零   
     88             }else{    
     89                 showPics(index);   
     90                 //如果索引值不等于li元素个数,按普通状态切换,调用showPics()   
     91             }   
     92             index++;   
     93         },3000);    
     94         //此3000代表自动播放的间隔,单位:毫秒也就是3秒   
     95     }).trigger("mouseleave");   
     96   
     97     //显示图片函数,根据接收的index值显示相应的内容   
     98     function showPics(index){     
     99     //普通切换   
    100         var nowLeft = -index*sWidth;    
    101         //根据index值计算ul元素的left值   
    102         $("#focus ul").stop(true,false).animate({"left":nowLeft},500);    
    103         //通过animate()调整ul元素滚动到计算出的position   
    104         $("#focus .btn span").removeClass("on").eq(index).addClass("on");   
    105          //为当前的按钮切换到选中的效果   
    106     }   
    107   
    108     function showFirPic(){    
    109     //最后一张图自动切换到第一张图时专用   
    110         $("#focus ul").append($("#focus ul li:first").clone());   
    111         var nowLeft = -len*sWidth;    
    112         //通过li元素个数计算ul元素的left值,也就是最后一个li元素的右边   
    113         $("#focus ul").stop(true,false).animate({"left":nowLeft},500,function(){   
    114         //通过callback,在动画结束后把ul元素重新定位到起点,然后删除最后一个复制过去的元素   
    115             $("#focus ul").css("left","0");   
    116             //定义样式距左为0  
    117             $("#focus ul li:last").remove();   
    118             //定义清除事件 清除所有的#focus ul li:last的ID   
    119         });    
    120         $("#focus .btn span").removeClass("on").eq(0).addClass("on");    
    121         //为第一个按钮添加选中的效果   
    122     }   
    123        
    124 });   
    125 </script>   
    126 </head>   
    127   
    128 <body>   
    129   
    130   
    131 <div class="demo">    
    132     <div id="focus">   
    133         <ul>   
    134             <li>   
    135                 <div style="left:0;top:0;"><a href="http://www.17sucai.com/"><img width="780" height="420" src="images/main1.png" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    136                    
    137             </li>   
    138             <li>   
    139                 <div style="left:0;top:0;"><a href="http://www.17sucai.com/"><img width="560" height="420" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    140                 <div style="right:0;top:0;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    141                 <div style="right:0;top:140px;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    142                 <div style="right:0;bottom:0;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    143             </li>   
    144             <li>   
    145                 <div style="left:0;top:0;"><a href="http://www.17sucai.com/"><img width="260" height="210" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    146                 <div style="left:260px;top:0;"><a href="http://www.17sucai.com/"><img width="260" height="210" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    147                 <div style="left:0;top:210px;"><a href="http://www.17sucai.com/"><img width="520" height="210" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    148                 <div style="right:0;top:0;"><a href="http://www.17sucai.com/"><img width="260" height="420" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    149             </li>   
    150             <li>   
    151                 <div style="left:0;top:0;"><a href="http://www.17sucai.com/"><img width="560" height="420" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    152                 <div style="right:0;top:0;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    153                 <div style="right:0;top:140px;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    154                 <div style="right:0;bottom:0;"><a href="http://www.17sucai.com/"><img width="220" height="140" src="images/main2.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    155             </li>   
    156             <li>   
    157                 <div style="left:0;top:0;"><a href="http://www.17sucai.com/"><img width="780" height="420" src="images/52525.jpg" alt="2012淘宝商城最新多格焦点图源代码" /></a></div>   
    158             </li>   
    159         </ul>   
    160     </div>   
    161 </div>   
    162 </body>
    163 </html>
  • 相关阅读:
    orale 函数大全[转] 涛
    easyuicombobox的option选项为true与false时的问题 涛
    数据库镜像转移Failover Partner 涛
    创建链接服务器 涛
    Sql Server 2008 R2 清空数据库中ldf日志文件 涛
    杂 涛
    Jquery 数组操作大全【转载】 涛
    VS2012常用快捷键 涛
    android studio集成ijkplayer Vevi
    CenOs 部署记录 Vevi
  • 原文地址:https://www.cnblogs.com/nin-w/p/5789783.html
Copyright © 2011-2022 走看看