JS+CSS打造的仿惠惠网带缓冲效果的图片滚动


<!DOCTYPE html>
    <html lang="en">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>JS+CSS打造的仿惠惠网带缓冲效果的图片滚动丨上谷战国红|亿诚</title>
    <style>* {margin:0;padding:0}</style>
    <!-- Jquery library -->
    <script type="text/javascript">
    window.onload=function(){
    var oTab=document.getElementById("tab-wrap");
    var oList=oTab.getElementsByTagName("ul")[0];
    var aLi=oTab.getElementsByTagName("li");
    var aImg=oTab.getElementsByTagName("img");
    var aDiv=oTab.getElementsByTagName("div");
    var sWidth=aImg[0].offsetHeight;
    var index=i=0;
    var timer=playTimer=null;
    var bOrder=true;
    var aTmp=[];
    var aLib=[0];
    var aClor=[["#DF2526","#00B5E4"],["#AAC901","#DF2018"],["#07FFF1","#FF650F"],["#9670C3","#49BCFD"]];
    //
    for(i=0;i<aLi.length;i++){
    aTmp.push("<li></li>")
    }
    var oCount=document.createElement("ul");
    oCount.className="count";
    oCount.innerHTML=aTmp.join("");
    oTab.appendChild(oCount);
    //
    var aBtn=oTab.getElementsByTagName("ul")[1].getElementsByTagName("li");
    for(i=0;i<aBtn.length;i++){
    aBtn[i].index=i;
    aBtn[i].onclick=function(){
    index=this.index;
    aLib.push(index);
    if(aLib.length>2){aLib.shift()};
    for(i=0;i<aBtn.length;i++){
    aBtn[i].className="";
    aLi[i].style.zIndex=100;
    aLi[i].style.display="none";
    }
    aBtn[index].className="current";
    aLi[index].style.zIndex=200;
    aLi[index].style.top=sWidth+"px";
    aLi[index].style.display="block";
    aLi[aLib[0]].style.display="block";
    aLi[index].style.background=aClor[index][0];
    aDiv[index].style.background=aClor[index][1];
    if(aLib[0]!=aLib[1]){
    showMove(aLi[index])
    }else {
    aLi[index].style.top=0;
    }
    }
    }
    //
    aBtn[index].className="current";
    aLi[index].style.zIndex=200;
    aLi[index].style.background=aClor[index][0];
    aDiv[index].style.background=aClor[index][1];
    autoPlay();
    //
    oTab.onmouseover=function(){
    clearInterval(playTimer);
    }
    oList.onmouseout=function(){
    autoPlay();
    }
    //
    function autoPlay(){
    playTimer=setInterval(function(){
    index==aBtn.length-1 && (bOrder=false);
    index==0 && (bOrder=true);
    bOrder ? index++ : index--;
    //console.log(index);
    aBtn[index].onclick();
    },5000)
    }
    //
    function showMove(obj){
    clearInterval(timer);
    timer=setInterval(function(){
    doMove(obj)
    },30)
    }
    //
    function doMove(obj){
    var iSpeed=obj.offsetTop/10;
    iSpeed=iSpeed>0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);
    obj.offsetTop<=0 ? clearInterval(timer) : obj.style.top=obj.offsetTop-iSpeed+"px";
    }
    }
    </script>
    <!-- Site styles -->
    <style>
    body{background:#000; text-align:center;font:12px/20px Arial;}
    #tab-wrap {width:100%;position:relative;overflow:hidden;}
    #tab-wrap .list {position:relative;height:252px;}
    #tab-wrap .list li {position:absolute;top:0;left:0;width:100%;height:252px;}
    #tab-wrap .list li img {margin:0 auto;width:990px;}
    #tab-wrap .list li .bg-right {position:absolute;top:0;right:0;width:50%;height:252px;z-index:-1;}
    #tab-wrap .count {position:absolute;left:50%;width:10px;height:100px;top:100px;margin-left:470px;z-index:300;}
    #tab-wrap .count li {float:left;width:10px;height:10px;background:#ccc;margin-bottom:10px;}
    #tab-wrap .count li:hover{cursor:pointer;}
    #tab-wrap .count li.current {background:#85BE2E;}
    </style>
    </head>
    <body>
    <div id="tab-wrap">
    <ul class="list">
    <li>
    <img src="/imagesforcode/201211/21116640990.jpg" width="990" height="252" />
    <div class="bg-right"></div>
    </li>
    <li>
    <img src="/imagesforcode/201211/211164436085.jpg" width="990" height="252" />
    <div class="bg-right"></div>
    </li>
    <li>
    <img src="/imagesforcode/201211/211171259810.jpg" width="990" height="252" />
    <div class="bg-right"></div>
    </li>
    <li>
    <img src="/imagesforcode/201211/211172831190.jpg" width="990" height="252" />
    <div class="bg-right"></div>
    </li>
    </ul>
    </div>
    </body>
    </html>
    <br><br><hr>
    

优质内容筛选与推荐>>
1、hihoCoder#1095(二分搜索)
2、Oracle SQL: displaying multiple column values per row
3、ASP.net四则运算《《《策略模式
4、Castle实践2-Startable Facility
5、右键菜单快速打开VS 2005 Website项目


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号