• jquery控制图片切换


    这种js现在用的很多。同时网上的js代码页很多。我直接从网上当了一个来用;代码如下:

    html

    <div class="bannerbox">
                    <div id="focus">
                        <ul>
                            <li><a href="#" target="_blank">
                                <img src="../images/index_18.gif" alt="" /></a></li>
                            <li><a href="#" target="_blank">
                                <img src="../images/index_18.gif" alt="" /></a></li>
                            <li><a href="#" target="_blank">
                                <img src="../images/index_18.gif" alt="" /></a></li>
                            <li><a href="#" target="_blank">
                                <img src="../images/index_18.gif" alt="" /></a></li>
                        </ul>
                    </div>
                </div>

    css:

    .bannerbox { 970px; height: 447px; overflow: hidden; margin: 0px auto; }
    #focus { border:none; 970px; height: 447px; clear: both; overflow: hidden; position: relative; float: left;z-index: 10 }
    #focus ul { 970px; height: 447px; float: left; position: absolute; clear: both; padding: 0px; margin: 0px; border: none}
    #focus ul li { float: left; 970px; height: 447px; overflow: hidden; position: relative; padding: 0px; margin:0;border: none }
    #focus .preNext { 550px; height: 440px; position: absolute; top: 2px; cursor: pointer;border: none;}
    #focus .pre { left: 0; background: url(../images/sprite.png) no-repeat left center;z-index: 20;border: none; }
    #focus .next { right: 0; background: url(../images/sprite1.png) no-repeat right center;z-index: 20;border: none; }

    jquery:

    $(function () {
        var sWidth = $("#focus").width();
        var len = $("#focus ul li").length;
        var index = 0;
        var picTimer;
        var btn = "<div class='btnBg'></div><div class='btn'>";
        for (var i = 0; i < len; i++) {
            btn += "<span></span>";
        }
        btn += "</div><div class='preNext pre'></div><div class='preNext next'></div>";
        $("#focus").append(btn);
        $("#focus .btnBg").css("opacity", 0);
        $("#focus .btn span").css("opacity", 0.4).mouseenter(function () {
            index = $("#focus .btn span").index(this);
            showPics(index);
        }).eq(0).trigger("mouseenter");
        $("#focus .preNext").css("opacity", 0.0).hover(function () {
            $(this).stop(true, false).animate({ "opacity": "0.5" }, 300);
        }, function () {
            $(this).stop(true, false).animate({ "opacity": "0" }, 300);
        });
        $("#focus .pre").click(function () {
            index -= 1;
            if (index == -1) { index = len - 1; }
            showPics(index);
        });
        $("#focus .next").click(function () {
            index += 1;
            if (index == len) { index = 0; }
            showPics(index);
        });
        $("#focus ul").css("width", sWidth * (len));
        $("#focus").hover(function () {
            clearInterval(picTimer);
        }, function () {
            picTimer = setInterval(function () {
                showPics(index);
                index++;
                if (index == len) { index = 0; }
            }, 2800);
        }).trigger("mouseleave");
        function showPics(index) {
            var nowLeft = -index * sWidth;
            $("#focus ul").stop(true, false).animate({ "left": nowLeft }, 300);
            $("#focus .btn span").stop(true, false).animate({ "opacity": "0.4" }, 300).eq(index).stop(true, false).animate({ "opacity": "1" }, 300);
        }
    });

    以上代码经测试在ie9以上,ff,chroom下运行正常。代码参考懒人图库

  • 相关阅读:
    【Web自动化测试——代码篇五】常用方法——鼠标键盘事件
    【Web自动化测试——代码篇四】常用方法——常见元素操作
    【Web自动化测试——代码篇三】常用方法——控制浏览器
    【Web自动化测试——代码篇二】条条大路找元素
    【Web自动化测试——代码篇一】简单的Web自动化脚本
    ON DUPLICATE KEY UPDATE 当记录不存在时插入,当记录存在时更新
    Replace INTO与INSERT INTO的不同之处
    JS 实现 Tab标签切换功能
    SQL LEFT JOIN 关键字
    php面向对象_get(),_set()的用法
  • 原文地址:https://www.cnblogs.com/lightinblack/p/3643843.html
Copyright © 2020-2023  润新知