基于jQuery实现搜狗壁纸焦点图切换



58 231 78



特效描述:基于jQuery实现 搜狗壁纸 焦点图切换,基于jQuery实现搜狗壁纸焦点图切换

代码结构

1. 引入CSS

<link href="css/wallpaper.css" type="text/css" rel="stylesheet">

2. 引入JS

<script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>

3. HTML代码

<div class="bannertop">
  <div class="bannerwin" id="bannerwin">
    <div class="bannerwrapper">
      <div class="bannercontent" id="forwin">
          <a class="windows_ico" id="btnplay0"></a>
          <a class="ios_ico" id="btnplay1"></a>
          <a class="android_ico" id="btnplay2"></a>
        <div class="forwait"></div>
        <span class="arrow"></span>
        <div class="forwin textdisp"></div>
        <a href="http://51qianduan.com" class="forwin downloadpc"></a>
            <span class="changeTime">
                <span class="times"></span>
                <span class="downtri"></span>
            </span>
        <div class="screenpc forwin"></div>
      </div>
    </div>
  </div>
  <div class="bannerandr" id="bannerandr">
    <div class="bannerwrapper">
      <div class="bannercontent" id="forandr">
          <a class="windows_ico" id="btnplay0"></a>
          <a class="ios_ico" id="btnplay1"></a>
          <a class="android_ico" id="btnplay2"></a>
      <span class="arrow"></span>
        <div class="andrtext forandroid"></div>
        <a href="http://51qianduan.com" class="downandroid forandroid"></a>
        <div class="androidDis forandroid"></div>
        <div class="androidcode forandroid"></div>
        <div class="scancode forandroid"></div>
        <a href="http://51qianduan.com" class="wandou forandroid" name="搜狗壁纸android版" title="通过豌豆荚下载"><img alt="豌豆荚一键安装" src="images/wandou.png"/></a></div>
    </div>
  </div>
  <div class="bannerios">
    <div class="bannerwrapper">
      <div class="bannercontent" id="banner0">
        <div class="forios iospart"></div>
        <a class="windows_ico" id="btnplay0"></a><a class="ios_ico" id="btnplay1"></a><a class="android_ico" id="btnplay2"></a>
        <div class="forwait"></div>
        <span class="arrow"></span>
        <div class="iphonepart">
          <div class="partwrapper">
            <div class="downloadup ioshide hoverstop"></div>
            <a class="downiphone iospart hoverstop" id="downiphone"></a>
            <div class="downloaddown ioshide hoverstop">
              <div class="innerIphone hoverstop">
                  <a class="dirdown hoverstop" href="http://51qianduan.com" title="直接下载,需越狱"></a>
                  <a class="istoredown hoverstop" href="http://51qianduan.com" title="官方下载"></a>
              </div>
            </div>
          </div>
        </div>
        <div class="ioswpart">
          <div class="partwrapper">
            <div class="ipadup ioshide hoverstop"></div>
            <a class="downipad iospart hoverstop" id="downipad"></a>
            <div class="ipaddown ioshide hoverstop">
              <div class="innerIpad hoverstop"> 
                    <a class="paddirdown  hoverstop" href="http://51qianduan.com" title="直接下载"></a>
                    <a class="istorepaddown hoverstop" target="_blank" href="http://www.51qianduan.com//cn/app/id641418313" title="官方下载"></a>
                </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript">
    $(function(){
        /* 按钮触碰效果 */
        function showSlideToggle(){
            if($("#downiphone").is(":animated")){
                return;
            }
            showTog(".downloadup",100);
            showTog(".downloaddown",200);
            changeIpPos();                                           
        }
        function changeIpPos(){
            $("#downiphone").toggleClass("active");   
            if($("#downiphone").hasClass("active")){
                $("#downiphone").css("backgroundPosition","-29px -152px");
            }else{
                $("#downiphone").css("backgroundPosition","-29px -30px");
            }
        }
        function showSlide(){
            if($("#downiphone").is(":animated")){
                return;
            }
            showDown(".downloadup",100);
            showDown(".downloaddown",200);
            $("#downiphone").addClass("active");
            $("#downiphone").css("backgroundPosition","-29px -152px");
        }
        function showTog(ele,speed){
            $(ele).slideToggle(speed);
        }
        function showDown(ele,speed){
            $(ele).slideDown(speed);
        }
        function showIpad(){
            if($("#downipad").is(":animated")){
                return;
            }
            showDown(".ipadup",100);
            showDown(".ipaddown",200);
            $("#downipad").addClass("active");
            $("#downipad").css("backgroundPosition","-205px -296px");
        }
        function showIpadToggle(){
            if($("#downiphone").is(":animated")){
                return;
            }
            showTog(".ipadup",100);
            showTog(".ipaddown",200);
            chgrIpadPos(true);
        }
        function chgrIpadPos(flag){
            $("#downipad").toggleClass("active");   
            if(!$("#downipad").hasClass("active")){
                $("#downipad").css("backgroundPosition","-29px -296px");
            }else{
                $("#downipad").css("backgroundPosition","-205px -296px");
            }
        }
        function hideIphone(){
            $(".downloadup").slideUp(200);
            $(".downloaddown").slideUp(200);
            $("#downiphone").removeClass("active");
            $("#downiphone").css("backgroundPosition","-29px -30px");
        }
        function hideIpad(){
            $(".ipadup").slideUp(200);
            $(".ipaddown").slideUp(200);
            $("#downipad").removeClass("active");
            $("#downipad").css("backgroundPosition","-29px -296px");
        }
        $("#downiphone").hover(function(){
            showSlide();
        });
        $("#downipad").hover(function(){
            showIpad();
        });
        $(".iphonepart").mouseleave(function(){
            hideIphone();
        });
        $(".ioswpart").mouseleave(function(){
            hideIpad();
        });
        /* 图片轮播效果,暂时注释掉轮播效果,只在点击时切换 */
        var timer = null;
        var interval = 8000;
        var stayTime = 7500;
        var len = 2;
        var index = 0;
        var timeoutRoll = null;
        $(".android_ico").click(function(){
            playAndroid();
            pb_component(click_gif,"androidTab",from);
        });
        $(".windows_ico").click(function(){
            playWindows();
            pb_component(click_gif,"winTab",from);
        });
        $(".ios_ico").click(function(){
            playIos();
            pb_component(click_gif,"iosTab",from);
        });
        var tag="";
        if(tag == "ios"){
            playIos();
        }else if(tag=="android"){
            playAndroid();
        }else{
            playWindows();
        }
        function clearTimer(){
            clearInterval(timer);
            clearTimeout(timeoutRoll);
        }
        function setNewInterval(){
            timer = setInterval(function(){
                index++;
                if(index == len){
                    index = 0;
                }
                play(index);
            },interval);
        }
        /* windows Banner背景图效果 */
        setCurBg();
        $(".changeTime").click(function(){
            clearTimer();
            var cur = getCurBg();
            cur++;
            if(cur > 12){
               cur = 1;
            }
            setBg(cur);
        });
        function getCurBg(){
            var bgstr = $(".bannerwin").css("backgroundImage");
            var preg = /\/(\d+)\.jpg/i;
            var res = bgstr.match(preg);
            if(res != false){
                return res[1];
            }
            /* 默认显示第一个时间点 */
            return 1;    
        }
        function getTimePos(i){
            if(i<=0 || i>13){
                i = 1;
            }
            var pos = ['-10px -10px','-67px -10px','-124px -10px','-181px -10px','-10px -108px','-67px -108px','-124px -108px','-181px -108px','-10px -206px','-67px -206px','-124px -206px','-181px -206px'];
            return pos[i-1];
        }
        /* 24小时转为时辰 */
        function getCurHour(){
            var hour = new Date().getHours();
            if(hour<0||hour>23){
                hour = 0;
            }
            var shour;
            if(hour==0 || hour ==23){
                shour = 1;
            }else{
                shour = Math.floor((hour+1)/2)+1;
            }
            return shour;
        }
        function setCurBg(){
            var cur = getCurHour();
            setBg(cur);
        }
        function setBg(cur){
            if(cur<1 || cur>12){
                cur = 1;
            }
            var bgscreen = getTimePos(cur);
            $(".bannerwin").css("backgroundImage","url(images/"+cur+".jpg)");
            $(".times").css("background-position",bgscreen);
            $(".screenpc").css("backgroundImage","url(images/bg"+'6'+".png)");
        }
        function play(index){
            if(index == 0){
                playIos();
                return;
            }
            playWindows();
        }
        function init(){
            $(".iospart").stop().css({"left":"2000px"});
            $(".forwin").stop().css("left","2000px");
            $(".forandroid").stop().css("left","2000px");
            $(".downloadup, .ipadup").stop().css({"height":"55px","display":"none"});
            $(".downloaddown, .ipaddown").stop().css({"height":"94px","display":"none"});
            $(".bannerios").css("left","100%");
            $(".bannerwin").css("left","100%");
            $(".bannerandr").css("left","100%");
            $(".ios_ico").removeClass("ios_active");
            $(".windows_ico").removeClass("windows_active");
            $(".android_ico").removeClass("android_active");
            $("#downipad").css("backgroundPosition","-29px -296px");
            $("#downiphone").css("backgroundPosition","-29px -30px");
            $(".ioshide").stop().fadeOut(10);
        }
        function initIos(){
            init();
            $(".arrow").css("left","498px");
            $(".bannerios").css("left","0");
            $(".ios_ico").addClass("ios_active");
        }
        function playIos(){
            initIos();
            $("#downiphone").animate({"left":"0"},400,function(){
                $("#downipad").animate({"left":"0"},400,function(){
                    $(".forios").show().css({"left":"482px"}).css({"opacity":1}).hide().fadeIn(1200); 
                });    
            });
        }
        function initWindows(){
            init();
            $(".windows_ico").addClass("windows_active");
            $(".arrow").css("left","439px");
            $(".bannerwin").css("left","0");
        }
        function playWindows(){
            initWindows();
            /* windows进入动画 */
            $(".screenpc").animate({"left":"52px"},400,function(){
                $(".downloadpc").animate({"left":"569px"},500);    
                $(".textdisp").animate({"left":"569px"},500);    
            });
        }
        function initAndroid(){
            init();
            $(".bannerandr").css("left","0");
            $(".android_ico").addClass("android_active");
            $(".arrow").css("left","557px");
        }
        function playAndroid(){
            initAndroid();
            $(".downandroid").animate({"left":"100px"},400);
            $(".wandou").animate({"left":"99px"},400);
            $(".androidcode").animate({"left":"0"},400);
            $(".scancode").animate({"left":"104px"},400);
            $(".andrtext").animate({"left":"0"},400,function(){
                $(".androidDis").animate({"left":"493px"},400);
            });
        }
        /* windos banner图片缓存 */
        for(var i = 1;i<=12;i++){
        /*
         * 1.如果new 在循环外,更改src会取消上次请求
         * 2.同一个image对象更改两次src,第二次会取消第一次的请求。
         * 3.由于每次生成image对象。请求地址后删除,释放资源 
         * 4.请求的资源较大,放在页面加载完毕后,且置于脚本最后
         * 5.申请的image临时对象请求之前不能unset。否则会取消src的图片请求
         */
        var image = new Image;
        var imagebg = new Image;
            image.src = "/images/"+i+".jpg";    
            imagebg.src = "/images/bg"+i+".png";
        }
    });
</script>
<div style="text-align:center;clear:both"><br>
</div>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 导航切换 带标题的焦点图 缩略图 带缩略图的幻灯片 图片相册 带简介的焦点图 图片切换 图片轮播 图片墙 文字切换 自动滚动图片轮播 百叶窗 背景切换 图片网格 马赛克幻灯片 手风琴 图片九宫格 全屏焦点图 选项卡自动切换 视频切换 图片高亮 列表切换 图片对比 图片文字 渐隐切换 单排图片 全屏切换 响应式图片 切换按钮 图片列表 缩放切换 图片拖动 图片放大镜 图片叠加 图片翻转旋转 图片延迟加载 图片淡出淡进 图片全屏 图片头像上传 二维码 滚动切换 滑动选项卡切换 图片广告 图片放大缩小 html5图片动画 带缩略图的幻灯片 地图 flash焦点图 图片滚动 图片滑动 图片切换 图片收缩展开 旋转木马 图片轮播 自动滚动图片轮播 图标导航菜单 选项卡切换 滑动手风琴 背景切换 手风琴 图表 焦点图幻灯片 图片 头像截图

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到