html+css+javascript实现渐隐轮播

   实现效果:

    图片自动轮播,点击左右按钮会操作图片向前或向后,图片与小圆点相互呼应,具有交互效果。

   编写思想:   

   实现交互时使用了排他思想,同选项卡的功能;

  自动轮播采用了setInterval()

   具体步骤参详代码:

代码:

css:


    <style>
        * {
            padding: 0;
            margin: 0;
            list-style: none;
            box-sizing: border-box;
        }

        #focus {
            width: 600px;
            height: 400px;
            background-color: orange;
            margin: 100px auto;
            position: relative;
            overflow: hidden;
        }

        #focus .pics {
            width: 100%;
            height: 100%;
        }

        #focus .pics li {
            width: 600px;
            height: 100%;
            text-align: center;
            font-size: 30px;
            line-height: 400px;
            opacity: 0;
            position: absolute;
            top:0;
            left:0;
            transition: all 0.3 ease;
        }
        #focus .pics li.on{
            opacity: 1;
        }

        #focus .circle {
            position: absolute;
            bottom: 20px;
            left: 50%;
            transform: translateX(-50%);

        }

        #focus .circle li {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            float: left;
            margin-left: 5px;
            background-color: #fff;
            text-align: center;
            line-height: 16px;
            box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.8);
        }

        #focus .circle li.active {
            background-color: orange;
        }

        #focus .prev, .next {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            display: block;
            width: 28px;
            height: 56px;
            background-color: rgba(255, 255, 255, 0.7);
            border-radius: 0 56px 56px 0;
            line-height:56px;
            font-size:20px;
            color:#fff;
        }

        #focus .next {
            right: 0;
            border-radius: 56px 0 0 56px;
            padding-left:8px;
        }
    </style>

html:

<div id="focus">
        <ul class="pics">
            <li style="background-color: rgb(179, 115, 115);" class="on">0</li>
            <li style="background-color: rgb(122, 122, 206);">1</li>
            <li style="background-color: rgb(92, 162, 92);">2</li>
        </ul>
        <ol class="circle">
        </ol>
        <span class="prev">&lt;</span>
        <span class="next">&gt;</span>
    </div>

js:

<script>
        //1.查节点
        var focus = document.querySelector('#focus');
        var pics = document.querySelector('.pics');
        var lis = document.querySelectorAll('.pics li');
        var circle = document.querySelector('.circle');
        var prev = document.querySelector('.prev');
        var next = document.querySelector('.next');
        //获取li宽度
        var liW = lis[0].offsetWidth;
        var time = null;
        //动态生成小圆点
        for (var i = 0; i < lis.length; i++) {
            var li = document.createElement('li');
            li.setAttribute('idx', i);
            circle.appendChild(li);
            //排他思想 选项卡
            li.onclick = function () {
                var active = document.querySelector('.circle li.active');
                active.classList.remove('active');
                this.classList.add('active');
                var idx = this.getAttribute('idx');
                //解决index与idx与cir之间的关系
                index = idx;
                cir = idx;
                document.querySelector('.pics li.on').classList.remove('on');
                lis[idx].classList.add('on');
            }
        }
        circle.children[0].classList.add('active');

        //2.添加功能
        //鼠标经过
        focus.onmouseenter = function () {
            prev.style.display = "block";
            next.style.display = "block";
            //鼠标经过时停止自动轮播
            clearInterval(time);
        }
        //鼠标离开
        focus.onmouseleave = function () {
            prev.style.display = "none";
            next.style.display = "none";
            //自动轮播
            time = setInterval(function () {
                next.onclick();
            }, 2500)
        }
        var index = 0;
        var cir = 0;
        //单击next箭头
        next.onclick = function () {
                if (index == lis.length - 1) {
                    //return;//图片到最后一张不再继续往下
                    index = -1;     
                }
                index++;

                document.querySelector('.pics li.on').classList.remove('on');
                lis[index].classList.add('on');

                //右按钮控制小圆点
                cir++;
                if (cir == circle.children.length) {
                    cir = 0;
                }
                run(cir);
            }
        //单击prev箭头
        prev.onclick = function () {
                if (index == 0) {
                    //return;//图片到最后一张不再继续往下
                    index = lis.length;
                    
                }
                index--;
                document.querySelector('.pics li.on').classList.remove('on');
                lis[index].classList.add('on');
               
                //左按钮控制小圆点
                cir--;
                if (cir == -1) {
                    cir = circle.children.length - 1;
                }
                run(cir);
            }
        //自动轮播
        time = setInterval(function () {
            next.onclick();
        }, 2500)

        // 左右箭头控制小圆点
        function run(cir) {
            // cir当前小圆点的索引号
            var active = document.querySelector('.circle li.active');
            active.classList.remove('active');
            // circle.children[cir]对应索引号的孩子
            circle.children[cir].classList.add('active');
        }
    </script>

运行结果:

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/252592.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

C++ summary 工具 Insights: 源码工具:应用篇 inline函数

介绍篇 在线执行 悬停&#xff0c;显示帮助 右键&#xff0c;查看文档 template example_1 int main(){int a 123;return 0; }(gdb) disas Dump of assembler code for function main():0x0000555555555129 <0>: endbr64 0x000055555555512d <4>: push …

2023年【陕西省安全员C证】新版试题及陕西省安全员C证复审模拟考试

题库来源&#xff1a;安全生产模拟考试一点通公众号小程序 陕西省安全员C证新版试题参考答案及陕西省安全员C证考试试题解析是安全生产模拟考试一点通题库老师及陕西省安全员C证操作证已考过的学员汇总&#xff0c;相对有效帮助陕西省安全员C证复审模拟考试学员顺利通过考试。…

C#有望成为2023年的编程语言之王

前言 TIOBE 2023年12月编程语言指数头条新闻&#xff1a;C#有望成为2023年的编程语言之王。 TIOBE是什么&#xff1f; 访问地址&#xff1a;https://www.tiobe.com/tiobe-index/ TIOBE是一个编程社区指数&#xff0c;用于衡量不同编程语言的受欢迎程度。TIOBE指数基于全球范围…

接口自动化测试框架【AIM】

最近在做公司项目的自动化接口测试&#xff0c;在现有几个小框架的基础上&#xff0c;反复研究和实践&#xff0c;搭建了新的测试框架。利用业余时间&#xff0c;把框架总结了下来。 AIM框架介绍 AIM&#xff0c;是Automatic Interface Monitoring的简称&#xff0c;即自动化…

pytest之allure测试报告02:allure具体使用方法

一、allure包含的方法 二、allure使用教程 &#xff08;1&#xff09;用例中写入allure方法 allure.epic("数据进制项目epic") allure.feature("手机号模块feature") class TestMobile:allure.story("杭州的手机号story")allure.title("测…

桌面概率长按键盘无法连续输入问题

问题描述&#xff1a;概率性长按键盘无法连续输入文本 问题定位&#xff1a; 系统按键流程分析 图一 系统按键流程 按键是由X Server接收的&#xff0c;这一点只要明白了X Window的工作机制就不难理解了。X Server在接收到按键后&#xff0c;会转发到相应程序的窗口中。在窗…

单片机——通信协议(UART协议解析篇)

一、引言 在嵌入式系统设计中&#xff0c;UART通信是一种广泛使用的串行通信协议&#xff0c;它通过两条信号线实现全双工的数据传输和接收。UART通信协议以其简单、灵活和易于集成的特点&#xff0c;在嵌入式设备之间以及与外部设备进行通信时发挥着重要作用。本文将详细介绍U…

VS Code连接远程Linux服务器调试C程序

1.在 VS Code 上安装扩展 C/C 2.通过 VS Code 连接远程 Linux 服务器 3.通过 VS Code 在远程 Linux 服务器上安装扩展 C/C 4.打开远程 Linux 服务器上的文件夹 【注】本文以 /root/ 为例。 5.创建项目文件夹&#xff0c;并在项目文件夹下创建C程序 6.按 F5&#xff0c;选…

浅显易懂 @JsonIgnore 的作用

1.JsonIgnore作用   在json序列化/反序列化时将java bean中使用了该注解的属性忽略掉 2.这个注解可以用在类/属性上   例如&#xff1a;在返回user对象时&#xff0c;在pwd属性上使用这个注解&#xff0c;返回user对象时会直接去掉pwd这个字段&#xff0c;不管这个属性有没…

Linux Shell——(脚本参数传递)

脚本参数传递 一、参数传值二、脚本文件中特殊的变量 总结 最近学习了shell脚本&#xff0c;记录一下shell脚本参数传递相关语法 一、参数传值 执行脚本的时候&#xff0c;可以向脚本传递参数&#xff0c;脚本内获取参数的格式为$n n位置从1开始&#xff0c;$0 是脚本的文件名…

(代码详解)绘制气泡图+详细讲解图例设置+如何正确理解气泡图+气泡大小、颜色+调参

目录 气泡图简介&#xff1a; 一、导入库 二、准备数据 三、画气泡图--基础版 四、画气泡图--进阶版一 (控制气泡大小) 解读气泡图&#xff1a; 五、画气泡图--进阶版二(控制气泡颜色) (一)用参数c控制气泡颜色 (二)用for循环的方法控制气泡颜色 (三)给气泡分配指定的颜…

FFmpeg——在Vue项目中使用FFmpeg(安装、配置、使用、SharedArrayBuffer、跨域隔离、避坑...)

个人简介 &#x1f440;个人主页&#xff1a; 前端杂货铺 &#x1f64b;‍♂️学习方向&#xff1a; 主攻前端方向&#xff0c;正逐渐往全干发展 &#x1f4c3;个人状态&#xff1a; 研发工程师&#xff0c;现效力于中国工业软件事业 &#x1f680;人生格言&#xff1a; 积跬步…

Kali Linux安装Xrdp远程桌面工具结合内网穿透实现远程访问Kali桌面

文章目录 前言1. Kali 安装Xrdp2. 本地远程Kali桌面3. Kali 安装Cpolar 内网穿透4. 配置公网远程地址5. 公网远程Kali桌面连接6. 固定连接公网地址7. 固定地址连接测试 前言 Kali远程桌面的好处在于&#xff0c;它允许用户从远程位置访问Kali系统&#xff0c;而无需直接物理访…

韩顺平学java第二阶段之BS框架002

这边讲了php都可以&#xff0c;反正就是打通双方的间隔就行了∑(っД;)っ卧槽&#xff0c;不见了

sap table 获取 valuation class MBEW 查表获取

参考 https://www.tcodesearch.com/sap-tables/search?qvaluationclass

尚硅谷Docker笔记-基础篇

B站视频&#xff1a;https://www.bilibili.com/video/BV1gr4y1U7CY 1.Docker简介 解决了运行环境和配置问题的软件容器 方便做持续集成并有助于整体发布的容器虚拟化技术 容器与虚拟机比较 Docker 容器是在操作系统层面上实现虚拟化&#xff0c;直接复用本地主机的操作系统…

12、ble_mesh_vendor_model 服务端,自定义模型

1、初始化流程&#xff0c;存储初始化&#xff0c;nvs擦除&#xff0c; board_init();初始化LED。 2、bluetooth_init();ble协议栈初始化 3、ble_mesh_get_dev_uuid(dev_uuid);//获取设备uuid加载到mac&#xff0c;后两位dev uuid 4、ble_mesh_init();//ble mesh协议栈初始化。…

使用Jemeter对HTTP接口压测

我们不应该仅仅局限于某一种工具&#xff0c;性能测试能使用的工具非常多&#xff0c;选择适合的就是最好的。笔者已经使用Loadrunner进行多年的项目性能测试实战经验&#xff0c;也算略有小成&#xff0c;任何性能测试&#xff08;如压力测试、负载测试、疲劳强度测试等&#…

关键点检测之修改labelme标注的json中类别名

import json import os import shutil#source_dir表示数据扩增之后的文件夹路径&#xff0c;此时标注的是多分类的标签 #new_dir表示转化之后得到的二分类文件夹def to2class():#json存放路径source_dir r1#json保存路径new_dir r1for i in os.listdir(source_dir):if i.ends…

十七、如何将MapReduce程序提交到YARN运行

1、启动某个节点的某一个用户 hadoopnode1:~$ jps 13025 Jps hadoopnode1:~$ yarn --daemon start resourcemanager hadoopnode1:~$ jps 13170 ResourceManager 13253 Jps hadoopnode1:~$ yarn --daemon start nodemanager hadoopnode1:~$ jps 13170 ResourceManager 15062 Jp…
最新文章