当前位置: 首页 > ai >正文

基于html+css+js+jquery实现轮播图(自动轮播,手动选择,翻页)

实现效果:

adver.html页面代码:

<!DOCTYPE html>

<html>

<head lang="en">

    <meta charset="UTF-8">

    <title> 广告图片轮播切换</title>

    <link rel="stylesheet" href="css/style.css">

    <script type="application/javascript" src="jquery-3.3.1.min.js"></script>

    <script type="text/javascript">

        var id = 1;

        function timer(){

            id = id%6+1;

            $("li:nth-of-type("+id+")").css('background','orange').siblings().css("background","#333333");

            $("div[class='adver']").css('background','url(images/adver0' + id + '.jpg)')

        }

        function over(i){

            id = i;

            $("li:nth-of-type("+i+")").css('background','orange').siblings().css("background","#333333");

            $("div[class='adver']").css('background','url(images/adver0' + i + '.jpg)')

            clearInterval(auto);

        }

        function out(){

            auto = setInterval(timer,2000);

        }

        function clkArrowLeft(){

            clearInterval(auto);

            id = id-1%6;

            if(id==0) id=6;

            $("li:nth-of-type("+id+")").css('background','orange').siblings().css("background","#333333");

            $("div[class='adver']").css('background','url(images/adver0' + id + '.jpg)')

            auto = setInterval(timer,2000);

        }

        function clkArrowRight(){

            clearInterval(auto);

            id = id%6+1;

            $("li:nth-of-type("+id+")").css('background','orange').siblings().css("background","#333333");

            $("div[class='adver']").css('background','url(images/adver0' + id + '.jpg)')

            auto = setInterval(timer,2000);

        }

    </script>

    <style>

        li{

            cursor: pointer;

        }

    </style>

</head>

<body>

<div class="adver">

    <ul>

        <li onmouseover="over(1);" onmouseout="out();">1</li>

        <li onmouseover="over(2);" onmouseout="out();">2</li>

        <li onmouseover="over(3);" onmouseout="out();">3</li>

        <li onmouseover="over(4);" onmouseout="out();">4</li>

        <li onmouseover="over(5);" onmouseout="out();">5</li>

        <li onmouseover="over(6);" onmouseout="out();">6</li>

    </ul>

    <!-- 手动轮播 -->

    <div class="arrowLeft" onclick="clkArrowLeft();">&lt;</div><div class="arrowRight" onclick="clkArrowRight();">&gt;</div>

</div>

</body>

<script type="text/javascript">

    //自动轮播

    var auto = setInterval(timer,2000);

</script>

</html>

style.css代码:

ul,li{padding: 0;margin: 0; list-style: none;

    -webkit-user-select:none;/*webkit浏览器*/

    -moz-user-select:none;/*火狐*/

    -ms-user-select:none;/*IE10*/

    user-select:none;}

.adver{margin: 0 auto; width: 700px; overflow: hidden; height: 454px; position: relative; background: url("../images/adver01.jpg");}

ul{position: absolute; bottom:10px; z-index: 100; width: 100%; text-align: center;}

ul li{display: inline-block; font-size: 10px; line-height: 20px; font-family: "΢���ź�"; margin: 0 1px; width: 20px; height: 20px; border-radius: 50%; background: #333333; text-align: center; color: #ffffff;}

.arrowLeft,.arrowRight{

    position: absolute;

    width: 30px;

    background:rgba(0,0,0,0.2);

    height: 50px;

    line-height: 50px;

    text-align: center;

    top:200px;

    z-index: 150;

    font-size: 28px;

    font-weight: bold;

    cursor: pointer;

    color:#ffffff;

    -webkit-user-select:none;/*webkit浏览器*/

    -moz-user-select:none;/*火狐*/

    -ms-user-select:none;/*IE10*/

    user-select:none;

    /* display: none; */

}

.arrowLeft{left: 10px;}

.arrowRight{right: 10px;}

li:nth-of-type(1){

    background: orange;

}

http://www.xdnf.cn/news/19895.html

相关文章:

  • #T1359. 围成面积
  • 华清远见25072班I/O学习day5
  • 嵌入式硬件 - 51单片机3
  • NotePad++下载安装与设置
  • 使用a标签跳转之后,会刷新一次,这个a标签添加的样式就会消失
  • 搞懂IFNULL 和 NULLIF
  • 【C++详解】异常概念、抛出捕获与处理机制全解析
  • 一文读懂数据分类分级:企业安全治理的基石
  • 深入理解Linux进程信号机制
  • 残差神经网络的案例
  • 【面试题】LangChain与LlamaIndex核心概念详解
  • 聚焦GISBox矢量服务:数据管理、数据库连接与框架预览全攻略
  • 分布式电源接入电网进行潮流计算
  • Linux笔记---UDP套接字实战:简易聊天室
  • 服务器不支持node.js16以上版本安装?用Docker轻松部署Node.js 20+环境运行Strapi项目
  • 新规则,新游戏:AI时代下的战略重构与商业实践
  • 安全领域必须关注每年发布一次“最危险的25种软件弱点”清单 —— CWE Top 25(内附2024 CWE Top 25清单详情)
  • Boost搜索引擎 数据清洗与去标签(1)
  • 【OpenHarmony文件管理子系统】文件访问接口mod_fs解析
  • ECMAScript(2)核心语法课件(Node.js/React 环境)
  • uniapp的上拉加载H5和小程序
  • PDF.AI-与你的PDF文档对话
  • C++虚函数虚析构函数纯虚函数的使用说明和理解
  • redisson延迟队列报错Sync methods can‘t be invoked from async_rx_reactive listeners
  • 快速排序算法详解
  • 【mysql】SQL自连接实战:查询温度升高的日期
  • 三维多相机光场扫描:打造元宇宙时代的“数字自我”
  • React学习教程,从入门到精通, React 嵌套组件语法知识点(10)
  • 公司机密视频泄露频发?如何让机密视频只在公司内部播放
  • 数据采集机器人哪家好?2025 年实测推荐:千里聆 RPA 凭什么成企业首选?