首页 > 其他分享 >jquery 轮播图,实现方式为:显示隐藏的方式

jquery 轮播图,实现方式为:显示隐藏的方式

时间:2023-10-09 20:56:36浏览次数:26  
标签:jquery index 轮播 方式 show function box height dingshi

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .box {
            width: 380px;
            height: 260px;
            position: relative;
        }

        .box-img {
            width: 380px;
            height: 260px;
            position: absolute;
            top: 0;
            left: 0;

            /*//图片都隐藏*/
            opacity: 0;
            transition: all 1.5s;
        }

        /*第一张显示*/
        .box-img:nth-child(1) {
            opacity: 1;
        }

        .box-left {
            width: 35px;
            height: 70px;
            color: #ccc;
            position: absolute;
            top: 100px;
            left: 0;
            line-height: 70px;

        }

        .box-right {
            width: 35px;
            height: 70px;
            color: #ccc;
            position: absolute;
            top: 100px;
            right: 0;
            line-height: 70px;
        }

        .box-left:hover, .box-right:hover {
            background: #00000050;
            color: #fff;
        }

        .box-zhiding {
            position: absolute;
            bottom: 10px;
            right: 10px;

        }

        .box-zhiding ul {
            margin: 0;
            padding: 0;
            list-style: none;
        }

        .box-zhiding li {
            width: 14px;
            height: 14px;
            border-radius: 100%;
            background: #ccc;
            float: left;
            margin-right: 10px;
        }

        .box-zhiding li:hover {
            background: #fff;
        }

        .current {
            background: red !important;
        }
    </style>
</head>
<body>

<div class="box">
    <div><img class="box-img" src="1.jpg" alt="" title="1"></div>
    <div><img class="box-img" src="2.jpg" alt="" title="2"></div>
    <div><img class="box-img" src="3.jpg" alt="" title="3"></div>
    <div><img class="box-img" src="4.jpg" alt="" title="4"></div>
    <div><img class="box-img" src="5.jpg" alt="" title="5"></div>

    <div class="box-left"> &lt;</div>
    <div class="box-right"> &gt;</div>

    <div class="box-zhiding">
        <ul>
            <li class="botton current"></li>
            <li class="botton"></li>
            <li class="botton"></li>
            <li class="botton"></li>
            <li class="botton"></li>
        </ul>
    </div>
</div>

<script src="https://cdn.bootcss.com/jquery/3.5.1/jquery.min.js"></script>
<script>
    $(function () {
        var index = 0;
        var length = $('.box-img').length - 1;
        dingshi()

        var f;

        function dingshi() {
            f = setInterval(function () {
                // 到头了
                if (index == length) {
                    index = 0;
                    show(index)
                } else {
                    index++;
                    show(index)
                }
            }, 4000)
        }


        $('.box-left').click(function () {
            clearInterval(f)
            if (index == 0) {
                index = length;
                show(index)
                dingshi()
            } else {
                index--;
                show(index)
                dingshi()
            }

        })
        $('.box-right').click(function () {
            clearInterval(f)
            if (index == length) {
                index = 0;
                show(index)
                dingshi()
            } else {
                index++;
                show(index)
                dingshi()
            }

        })

        $('.botton').click(function () {
            clearInterval(f)
            var indexx = $(this).index()
            index = indexx
            show(index)
            dingshi()
        })

        function show(index) {
            $('.box-img').css("opacity", "0");
            $('.box-img').eq(index).css("opacity", "1");

            $('.botton').removeClass('current').eq(index).addClass('current');

        }
    })
</script>

</body>
</html>

标签:jquery,index,轮播,方式,show,function,box,height,dingshi
From: https://www.cnblogs.com/photo520/p/17753116.html

相关文章

  • 【Azure Key Vault】在Azure Databricks上获取Azure Key Vault中所存储的机密(secret)
    问题描述在AzureDatabricks上获取AzureKeyVault中所存储的机密(secret)的两种方式? 问题解答方式一:在Databricks的Notebook中,直接编写Python代码读取KeyVault的Secret实例代码如下:importosfromazure.keyvault.secretsimportSecretClientfromazure.identityim......
  • 创建线程的三种方式
    「有点收获」三种基本方法创建线程(qq.com)创建线程的三种方法线程英译是Thread,这也是Java中线程对应的类名,在java.lang包下。注意下它实现了Runnable接口,下文会详细解释。线程与任务合并——直接继承Thread类线程创建出来自然是需要执行一些特定的任务的,一个线程......
  • 查询手机号所属地,支持多种查询方式的API接口
    在现代社会,手机号已经成为人们生活和工作中不可缺少的一部分。而一个手机号可以初步反映出该号码的归属地信息。因此,查询手机号所属地已经成为人们日常生活中的常见需求。本篇文章将通过介绍一个支持多种查询方式的API接口来帮助读者更好地了解查询手机号所属地的相关知识。 ......
  • JqueryDatatable插件
    注意:要被dataTable处理的table对象,必须有thead与tbody,而且,结构要规整(数据不一定要完整),这样才能正确处理常用参数'bPaginate':true,//是否显示分页'sPaginationType':"full_numbers",//分页的类型'iDisplayLength':50,//每页显示数量'bFilter':false,//是否启动过滤......
  • JQuery基础系统二:选择器
    选择器是jQuery的基础,在jQuery中,对事件处理、遍历DOM和Ajax操作都依赖于选择器1.CSS选择器1.1CSS是一项出色的技术,它使得网页的结构和表现样式完全分离。利用CSS选择器可以轻松的对某个元素添加样式而不用改动HTML结构,只需要通过添加不同的CSS规则,就可以得到不同样式的网页1.......
  • JQuery基础系统一:简介
    jQueryAPI中文文档:https://www.jquery123.com/jQueryMobile菜鸟教程:http://www.runoob.com/jquerymobile/jquerymobile-tutorial.html更多内容参考Github:https://github.com/summerSongXia/summerProject/tree/master/JQuery1.Javascript简介1.1JS的3个弊端:复杂的......
  • jquery之each遍历
    jQuery的each和原生的JavaScript方法forEach原生的JavaScript方法forEach是EcmaScript5提供的不兼容IE8jQuery的each由jQuery这个第三方库提供jQuery2以下的版本是兼容IE8的它的each方法主要用来遍历jQuery实例对象(伪数组)同时它也可以作为......
  • Spring中有哪些依赖注入的方式
    Spring中有哪些依赖注入的方式有2种实现方式:注解(如@Autowired,@Resource,@Required)配置文件(如xml)1.注解:@ComponentpublicclassMyService{privateDependencydependency;@AutowiredpublicMyService(Dependencydependency){this.d......
  • docker - 多个docker通过非IP方式连接方式
    二、多个docker通过非IP方式连接方式:有一个web容器、一个mysql容器,web服务器需要访问mysql容器,从上面的方式,可以知道使用IP来访问.局限:①.每次部署或启动,相同容器的IP会发生变化②.需要先知道ip才能进行通信1.link(官方已经废弃,原理可参考):采用link来为mysql容器起个na......
  • jquery 直接添加<style>样式
    如何使用jQuery直接添加style样式作为一名经验丰富的开发者,我将带你了解如何使用jQuery直接添加style样式。在本文中,我将向你展示一个简单的步骤,并提供每一步所需的代码和注释。让我们开始吧!整体流程下面是整个过程的步骤概述:步骤描述1引入jQuery库2创建一个样式......