2020 用html JavaScript实现广告轮播图切换 鼠标悬浮下标且左右切换图片

news/2024/7/19 15:04:06 标签: html, javascript, js, css

html_JavaScript__0">用html JavaScript实现广告轮播图切换 鼠标悬浮下标且左右切换图片

如图所示,左右有箭头可以切换照片,鼠标悬浮下标数字可跳转图片

在这里插入图片描述

建一个style.css文件

ul,li{padding: 0;margin: 0; list-style: none;}
.adver{margin: 0 auto; width: 700px; overflow: hidden; height: 454px; position: relative; background: url("../img/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-family: "微软雅黑";
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    
}
.arrowLeft{left: 10px;}
.arrowRight{right: 10px;}
li:nth-of-type(1){
    background: orange;
}

html代码

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>图片轮播切换</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="js/jquery-3.5.1.js" type="text/javascript"></script>
    <script type="text/javascript">
    
    //by 夜林 2020.11.3
	
  $(function () {
    //记录当前位置
    var index = 0;
    //显示左右侧按钮
    $(".adver").hover(function () {
      $(".arrowLeft,.arrowRight").toggle();
    })
    //左侧按钮
    $(".arrowLeft").click(function () {
      index--;
      if (index < 0) {
        index = 5;
      }
      $(".adver").css("background","url(img/adver0" + (index+1) + ".jpg)");
      $("ul li:nth-of-type("+(index+1)+")").css("background","orange").siblings().css("background","black");
    });
    //右侧按钮
    $(".arrowRight").click(function () {
      index++;
      if(index > 5) {
        index = 0;
      }
      $(".adver").css("background","url(img/adver0" + (index+1) + ".jpg)");
      $("ul li:nth-of-type("+(index+1)+")").css("background","orange").siblings().css("background","black");
    });
    //切换图片
    $("ul li").hover(function () {
      index = $(this).index();
      $(".adver").css("background","url(img/adver0" + (index+1) + ".jpg)");
      $("ul li:nth-of-type("+(index+1)+")").css("background","orange").siblings().css("background","black");
    });
  
    //移入暂停和移出恢复定时滚动
    $(".adver").mousemove().mouseout();
    

    
  })
</script>
</head>
<body>
<div class="adver">
    <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
        <li>6</li>
    </ul>
    <div class="arrowLeft"><</div><div class="arrowRight">></div>
</div>
</body>
</html>




推荐

js 正则表达式做一个前端注册表单信息验证

使用HTML DOM实现对订单表格的增删查改


http://www.niftyadmin.cn/n/1463375.html

相关文章

2020 Linux 编写一个显示菜单的shell程序,利用函数实现简单的菜单功能,n的值由键盘输入:

(1)在后台启动一个任务(例如vi test.txt&)然后用jobs命令列出任务,并用fg命令将任务切换到前台运行。 (2)在前台运行一个时间较长任务,如find / -name *.c,然后用ctrl-z将其挂起,用ps命令查看进程情况。 (13)在2019年12月12日0点0分(注:具体时间可根据实际…

2020 用html jQuery实现广告轮播图自动切换 滚动页面 鼠标悬浮下标且左右切换图片

用html jQuery实现广告轮播图自动切换 滚动页面 运行图片 代码 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv"Content-Type&qu…

2020解决表格重载tableIns.reload序列化serialize()后 前端给后端传中文时的中文乱码问题

解决表格重载tableIns.reload序列化serialize()后 前端给后端传中文时的中文乱码问题 最近遇到的问题&#xff0c;使用表格序列化serialize()后&#xff0c;表格重载发送数据&#xff0c;后台无法接收中文问题 处理函数 前端 前端查询无结果&#xff0c;f12看下控制台&…

2020 blur()和onblur的使用区别

blur()和onblur的使用区别 一、 blur()是jQuery 的方法&#xff0c;直接绑定对象&#xff1b; 实例&#xff1a; $(selector).blur() 当输入域input失去焦点 (blur) 时改变其颜色&#xff1a; $("input").blur(function(){$("input").css("backgr…

2020 使用jquery形式的Ajax+servlet实现简单用户名自动提示功能(可自加后台dao查找数据库)

使用jquery形式的Ajaxservlet实现简单用户名自动提示功能(可自加后台dao查找数据库) 演示&#xff1a; AjaxServlet.java package servlet;import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; impo…

2020 html()和innerHTML使用区别

html()和innerHTML使用区别 一、html() html() 方法设置或返回被选元素的内容。 当该方法用于返回内容时&#xff0c;则返回第一个匹配元素的内容。 当该方法用于设置内容时&#xff0c;则重写所有匹配元素的内容。 返回内容&#xff1a; $(selector).html() 设置conten…

2020 报错javax.el.PropertyNotFoundException: Property ‘XXX‘ not found on type bean.XXXXX

解决javax.el.PropertyNotFoundException: Property ‘XXX’ not found on type bean.XXXXX报错问题 做javaweb项目时&#xff0c;遇到这个错误&#xff0c;运行不了&#xff0c;初步分析为数据库里的字段名和实体类的属性名不同的问题。 1.打开数据库&#xff0c;其中发现字…

2020 Maven环境下log4j日志的详细配置

Maven环境下log4j日志的详细配置 1.在pom.xml里配置 <!--log4j--><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>${log4j.version}</version></dependency><dependency><gr…