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

news/2024/7/10 23:43:32 标签: html, jquery

html_jQuery__0">用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" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<style>
	*{
		margin:0px;
		padding:0px;
	}
	#d1{
		border : 1px solid #aaaaaa;
		margin-left:200px;
		margin-top:40px;
		width:970px; 
		height:300px; 
		overflow:hidden;
		position:relative;
	}
	
	#adv,#num{
		position:absolute;
	}
	
	ul li{
		list-style:none;
		display:inline;
	}
	ul img{
		width:970px; 
		height:300px;
		display:block;
	}
	
	#num{
		
		right:300px;
		bottom:5px;
	}
	
	#num li{
		float: left;
		color: blue;
		text-align: center;
		line-height: 16px;
		width: 16px;
		height: 16px;
		font-family: Arial;
		font-size: 12px;
		cursor: pointer;
		overflow: hidden;
		margin: 3px 1px;
		border: 1px solid #FF7300;
		
	}
	
	.on{
		line-height: 21px;
		width: 21px;
		height: 21px;
		font-size: 16px;
		margin: 0 1px;
		border: 0;
		background-color:navajowhite;
		font-weight: bold;
	}
	#main{text-align:center; width: 1014px; margin: 0 auto;}
#adver{
	position:absolute;
	left:10px;
	top:30px;
	z-index:2;
}
</style>

<script type="text/javascript" src="js/jquery-3.5.1.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
		var adverTop=parseInt($("#adver").css("top"));
		var adverLeft=parseInt($("#adver").css("left"));
		$(window).scroll(function(){
			var scrollTop = parseInt($(this).scrollTop());//获取滚动条翻上去的距离
			var scrollLeft = parseInt($(this).scrollLeft());//获取滚动条向右的距离
			$("#adver").offset({top:scrollTop+adverTop});
			$("#adver").offset({left:scrollLeft+adverLeft});
		});
	});
	
	$(function(){
		$('#num li').mouseenter(function(){
			//取得光标指向的li的下标
			var index = $('#num li').index(this);
			//滚动图片
			showImage(index);
		}).eq(0).mouseenter();//鼠标进来的时候显示第一个
		
		var i = 0;
		var taskId;
		
		$('#d1').hover(function(){
			//光标进入,停止滚动
			clearInterval(taskId);
		},function(){
			//设置间隔时间
			taskId = setInterval(function(){
				showImage(i);
				i++;
				if(i==5){//如果是最后
					i = 0;//回到首张
				}
			},1000);//设置1秒
		}).mouseleave();//光标离开,开始滚动
	});
	
	function showImage(index){
		$('#adv').stop(true).animate({'top':-index * 300},1000);//stop(true):清空当前累积的所有的动画。
		//取选中索引为index的来加样式on高亮且其余li同级元素来移除没有高亮光标
		$('#num li').eq(index).addClass('on').siblings().removeClass('on');
	}
</script>
</head>
<body>
	<div id="d1">
		<ul id="adv">
			<li><img src="img/adver01.jpg"/></li>
			<li><img src="img/adver02.jpg"/></li>
			<li><img src="img/adver03.jpg"/></li>
			<li><img src="img/adver04.jpg"/></li>
			<li><img src="img/adver05.jpg"/></li>
		</ul>
		<ul id="num">
			<li>1</li>
			<li>2</li>
			<li>3</li>
			<li>4</li>
			<li>5</li>
		</ul>
	</div>

<div id="main"><img src="img/main1.jpg"/><img src="img/main2.jpg"/><img src="img/main3.jpg"/></div>
</body>
</html>

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

相关文章

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…

2020 Mybatis 参数 useGeneratedKeys=“true“ keyProperty=“id“,插入后又同时获取新增数据后自增的id?

后端controller如何使用useGeneratedKeys“true” keyProperty“id”&#xff0c;插入后又同时获取新增数据后自增的id&#xff1f; Mybatis 配置文件 useGeneratedKeys 参数只针对 insert 语句生效&#xff0c;默认为 false。当设置为 true 时&#xff0c;表示如果插入的表以…

2020 @JsonFormat 和@DateTimeFormat的使用区别讲解

JsonFormat 和DateTimeFormat的使用区别 1.JsonFormat 用于后端从数据库里拿出来的时间传给前端的时间格式转换 JsonFormat(pattern "yyyy-MM-dd HH:mm:ss",timezone "GMT8")2.DateTimeFormat 用于前端页面传给后端的时间格式转换 DateTimeFormat(patte…