jQuery 实现焦点图(banner)

摘要:
*{margin:0;padding:0;list-style:none;}#div1{100%;background:url(1.jpeg)centertopno-repeat;height:368px;position:relative;text-align:center;}#div1div{30px;height:80px;background-color:#000;position:absolute;color:#fff;font-size:40px;line-height:80px;text-align:center;}#leftbtn{top:144px;}#rightbtn{top:144px;right:0px;}#nav{position:absolute;350px;top:345px;left:50%;margin-left:-130px;}#navli{40px;height:4px;float:left;background-color:#fff;margin-left:10px;}functionstyle($){$(".drop").css("backgroundColor","#fff");}$(function(){varimgs=["1.jpeg","2.jpeg","3.jpeg","4.jpeg","5.jpeg"];$(".drop").eq(0).css("backgroundColor","#000");$(".drop").each(function(i){$(".drop").eq(i).mouseover(function(){style($);$(this).css("backgroundColor","#000");$("#div1").css("backgroundImage","url("+imgs[i]+")");});});varindex=0;$("#rightbtn").click(function(){index++;if(index˃imgs.length-1){index=0;}$("#div1").css("backgroundImage","url("+imgs[index]+")");style($);$(".drop").eq(index).css("backgroundColor","#000");clearInterval(timeout);timeout=setInterval(show2,2000);})varindex=imgs.length-1;$("#leftbtn").click(function(){index--;if(indeximgs.length-1){i=0;}}varindex=0;functionshow2(){style($);$(".drop").eq(index).css("backgroundColor","#000");$("#div1").css("backgroundImage","url("+imgs[index]+")");index++;if(index˃imgs.length-1){index=0;}}vartimeout=setInterval(show1,2000);//每隔2秒改变一次$(".drop").mouseover(function(){clearInterval(timeout);timeout=setInterval(show2,2000);index=$(this).index(".drop");})})˂˃
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <meta charset="utf-8" />
    <script src="JS/jquery-3.3.1.min.js"></script>
    <style>
        *{
            margin: 0;
            padding: 0;
            list-style: none;
        }

        #div1 {
             100%;
            background: url(1.jpeg) center top no-repeat;
            height: 368px;
            position: relative;
            text-align: center;
        }

            #div1 div {
                 30px;
                height: 80px;
                background-color: #000;
                position: absolute;
                color: #fff;
                font-size: 40px;
                line-height: 80px;
                text-align: center;
            }

        #leftbtn {
            top: 144px;
        }

        #rightbtn {
            top: 144px;
            right: 0px;
        }

        #nav {
            position: absolute;
             350px;
            top: 345px;
            left: 50%;
            margin-left: -130px;
        }

            #nav li {
                 40px;
                height: 4px;
                float: left;
                background-color: #fff;
                margin-left: 10px;
            }
    </style>
    <script>function style($) {
            $(".drop").css("backgroundColor", "#fff");
        }


        $(function () {
            var imgs = ["1.jpeg", "2.jpeg", "3.jpeg", "4.jpeg", "5.jpeg"];
            $(".drop").eq(0).css("backgroundColor", "#000");
            $(".drop").each(function (i) {
                $(".drop").eq(i).mouseover(function () {
                    style($);
                    $(this).css("backgroundColor", "#000");
                    $("#div1").css("backgroundImage", "url(" + imgs[i] + ")");
                });
            });


            var index = 0;            
            $("#rightbtn").click(function () {                
                index++;         
                if (index > imgs.length-1) {
                    index = 0;
                }
                $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                style($);
                $(".drop").eq(index).css("backgroundColor", "#000");
                clearInterval(timeout);
                timeout = setInterval(show2, 2000);             
            })


            var index = imgs.length - 1;
            $("#leftbtn").click(function () {
                index--;
                if (index < 0) {
                    index = imgs.length - 1;
                }
                $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                style($);
                $(".drop").eq(index).css("backgroundColor", "#000");
                clearInterval(timeout);
                timeout = setInterval(show2, 2000);
            })


            var i = 0;
            function show1() {
                $("#div1").css("backgroundImage", "url(" + imgs[i] + ")");
                style($);
                $(".drop").eq(i).css("backgroundColor", "#000");
                i++;
                if (i > imgs.length - 1) {
                    i = 0;
                }             
            }
            var index=0;
            function show2() {               
                style($);
                $(".drop").eq(index).css("backgroundColor", "#000");
                $("#div1").css("backgroundImage", "url(" + imgs[index] + ")");
                index++;
                if (index> imgs.length - 1) {
                    index = 0;
                }
               
            }
            var timeout = setInterval(show1, 2000);//每隔2秒改变一次
$(".drop").mouseover(function () {
                clearInterval(timeout);
                timeout = setInterval(show2, 2000);
                index= $(this).index(".drop");
            })         
        })
    </script>
</head>
<body>
    <div id="div1">
        <a href="#"> <div id="leftbtn"><</div></a>
        <a href="#"><div id="rightbtn">></div></a>
    </div>
    <ul id="nav">
        <li class="drop"></li>
        <li class="drop"></li>
        <li class="drop"></li>
        <li class="drop"></li>
        <li class="drop"></li>
    </ul>

</body>
</html>

免责声明:文章转载自《jQuery 实现焦点图(banner)》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇vbs实现unicode和ascii的转化趋势买卖--主图叠加下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Downloading jQuery 3.2.1

Downloading jQuery Compressed and uncompressed copies of jQuery files are available. The uncompressed file is best used during development or debugging; the compressed file saves...

常用移动web开发框架--转载

  阅读目录 1.1 jQuery mobile flat-ui 主题 1.2jQuery mobile Bootstrap 主题 4.1 GMU   4.2 Clouda+  4.3 efe    5.1 Spirit 5.2 Frozen UI       纯粹的总结一下移动web开发框架,移动web开发框架有jQuery Mobile 、...

jQuery FileUpload 插件[转]

jQuery FileUpload 插件 在前端开发过程中,我们经常要上传文件,这是我们就要用<input type="file" name="file">这是原生的写法,看起来不是很美观。下面我们聊一种比较优雅的实现方法。 上传文件 首先,我们隐藏的input框,并将input框的click事件绑定到它上面的button元素上(通过oncl...

jquery 左右移动 以及使用layer.js弹出框呈现在页面上

今天写了一个左右移动 但是发现自己写的css效果一直都加不上去,不管了,还是先上自己有问题的代码,毕竟在失败中发现问题也是一种成长么。好吧,其实我们都知道在列表有边框里,它的值来源于左边框,那么如果我这样 yidong.click(function(){ $(this).css("backgroundColor",'#3385ff');//...

封装两个简单的Jquery组件

Jquery给我们提供了很大的方便,我们把他看成是一个公共库,以致在这个公共库上延伸出了很多Jquery插件;在项目过程中,有些插件总是不那么令人满意; 主要说两个项目用途: 1、 遮罩层,跟一般的遮罩层不一样,我需要实现的是对某一个元素进行局部遮罩; 2、 冒泡提示,网上有很多,我需要的只是一种在页面指定位置弹出来的一个静止定位的div而已;两个就自己了...

jQuery操作json数据

json是一种轻量级数据交换格式,简单的json格式为[{"key1":"value1"},{"key2":"value2"}], []代表数组,{}代表数组中的数据对象,key1,key2是一个json对象中的key,一个json中key值唯一,value1,value2,是key键对应的值。 下面使用jquery解析简单的son文件。 这里是songs...