轮播图表面样式
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/7420c52d2761b2fd04a43a88e87e6ff2.jpeg)
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
.transfrom_image{
width: 420px;
height: 200px;
margin: 0 auto;
}
a{
text-decoration: none;
color: black;
}
.img{
display: block;
width: 420px;
height: 200px;
background-size: 420px 200px;
background-image: url(images/03.png);
}
.left, .right{
display: block;
height: 20px;
line-height: 20px;
background-color: white;
opacity: 0.5;
position: absolute;
text-align: center;
top: 50%;
margin-top: -10px;
}
.left{
left: 0;
}
.right{
right: 0;
}
.bottom{
position: absolute;
bottom: 10px;
left: 50%;
margin-left: -35px;
width: 70px;
height: 10px;
background-color: white;
opacity: 0.5;
border-radius: 20px;
}
.bottom div{
display: inline-block;
width: 8px;
height: 8px;
margin: 1px;
margin-left: 4px;
margin-bottom: 8px;
border-radius: 50%;
background-color: black;
}
.bottom div:hover{
background-color: #7fffd4;
}
</style>
</head>
<body>
<div style="position: relative;" class="transfrom_image">
<a class="img" href=""></a>
<a class="left" href=""><</a>
<a class="right" href="">></a>
<div class="bottom">
<div ></div>
<div></div>
<div></div>
<div></div>
</div>
</div>
</body>
</html>
轮播图的小点
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/60718da4e1a14abed326cc0f51fd7079.jpeg)
<a class="pic1 fl" href="">
<button class="lb"><</button>
<button class="rb">></button>
<div class="circle">
<span class="awake"></span><span></span><span></span><span></span><span></span>
</div>
</a>
#display .center .first .pic1 .circle{
position: absolute;
bottom: 15px;
left: 50%;
border-radius: 10px;
padding: 3px 0;
font-size: 0;
margin-left: -35px;
background-color: rgba(255,255,255,0.3);
}
#display .center .first .pic1 .circle span{
display: inline-block;
width: 8px;
height: 8px;
border-radius: 50%;
background-color: #fff;
margin: 0 3px;
cursor: pointer;
}
#display .center .first .pic1 .circle .awake{
background-color: #ff5000;
}
#display .center .second{
margin: 10px 10px 0 10px;
width: 690px;
height: 230px;
}
简单轮播图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9d1c29cc1a6b9f5a98acb80fd93b3de2.jpeg)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0
}
ul {
list-style: none
}
img {
vertical-align: top
}
.box {
width: 730px;
height: 454px;
margin: 100px auto;
padding: 5px;
border: 1px solid #ccc;
}
.inner {
width: 730px;
height: 454px;
background-color: pink;
overflow: hidden;
position: relative;
}
.inner ul {
width: 1000%;
position: absolute;
top: 0;
left: 0;
}
.inner li {
float: left;
}
.square {
position: absolute;
right: 10px;
bottom: 10px;
}
.square span {
display: inline-block;
width: 16px;
height: 16px;
background-color: #fff;
text-align: center;
line-height: 16px;
cursor: pointer;
}
.square span.current {
background-color: orangered;
color: #fff;
}
</style>
</head>
<body>
<div class="box" id="box">
<div class="inner"><!--相框-->
<ul>
<li><a href="#"><img src="images/1.jpg" alt=""/></a></li>
<li><a href="#"><img src="images/2.jpg" alt=""/></a></li>
<li><a href="#"><img src="images/3.jpg" alt=""/></a></li>
<li><a href="#"><img src="images/4.jpg" alt=""/></a></li>
<li><a href="#"><img src="images/5.jpg" alt=""/></a></li>
<li><a href="#"><img src="images/6.jpg" alt=""/></a></li>
</ul>
<div class="square">
<span class="current">1</span>
<span>2</span>
<span>3</span>
<span>4</span>
<span>5</span>
<span>6</span>
</div>
</div>
</div>
<script>
var box=document.getElementById("box");
var inner=box.children[0];
var imgWidth=inner.offsetWidth;
var ulObj=inner.children[0];
var spanObjs=inner.children[1].children;
for(var i=0;i<spanObjs.length;i++){
spanObjs[i].setAttribute("index",i);
spanObjs[i].onmouseover=function () {
for(var j=0;j<spanObjs.length;j++){
spanObjs[j].removeAttribute("class");
}
this.className="current";
var index=this.getAttribute("index");
animate(ulObj,-index*imgWidth);
};
}
function animate(element, target) {
clearInterval(element.timeId);
element.timeId = setInterval(function () {
var current = element.offsetLeft;
var step = 10;
step = current < target ? step : -step;
current += step;
if (Math.abs(current - target) > Math.abs(step)) {
element.style.left = current + "px";
} else {
clearInterval(element.timeId);
element.style.left = target + "px";
}
}, 20);
}
</script>
</body>
</html>
左右焦点轮播图
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/d45abd4d29ed71d930695ed25a49cbb3.jpeg)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style>
body, ul, ol, li, img {
margin: 0;
padding: 0;
list-style: none;
}
#box {
width: 520px;
height: 280px;
padding: 5px;
position: relative;
border: 1px solid #ccc;
margin: 100px auto 0;
}
.ad {
width: 520px;
height: 280px;
overflow: hidden;
position: relative;
}
#box img {
width: 520px;
}
.ad ol {
position: absolute;
right: 10px;
bottom: 10px;
}
.ad ol li {
width: 20px;
height: 20px;
line-height: 20px;
border: 1px solid #ccc;
text-align: center;
background: #fff;
float: left;
margin-right: 10px;
cursor: pointer;
_display: inline;
}
.ad ol li.current {
background: yellow;
}
.ad ul li {
float: left;
}
.ad ul {
position: absolute;
top: 0;
width: 2940px;
}
.ad ul li.current {
display: block;
}
#focusD {
display: none;
}
#focusD span {
width: 40px;
height: 40px;
position: absolute;
left: 5px;
top: 50%;
margin-top: -20px;
background: #000;
cursor: pointer;
line-height: 40px;
text-align: center;
font-weight: bold;
font-family: '黑体';
font-size: 30px;
color: #fff;
opacity: 0.3;
border: 1px solid #fff;
}
#focusD #right {
right: 5px;
left: auto;
}
</style>
</head>
<body>
<div id="box" class="all">
<div class="ad">
<ul id="imgs">
<li><img src="images/01.jpg"/></li>
<li><img src="images/02.jpg"/></li>
<li><img src="images/03.jpg"/></li>
<li><img src="images/04.jpg"/></li>
<li><img src="images/05.jpg"/></li>
</ul>
</div><!--相框-->
<div id="focusD"><span id="left"><</span><span id="right">></span>
</div>
</div>
<script>
var box = document.getElementById("box");
var ad = box.children[0];
var imgWidth = ad.offsetWidth;
var ulObj = ad.children[0];
var focusD = document.getElementById("focusD");
box.onmouseover = function () {
focusD.style.display = "block";
};
box.onmouseout = function () {
focusD.style.display = "none";
};
var index=0;
document.getElementById("right").onclick = function () {
if(index<ulObj.children.length-1){
index++;
animate(ulObj,-index*imgWidth);
}
};
document.getElementById("left").onclick = function () {
if(index>0){
index--;
animate(ulObj,-index*imgWidth);
}
};
function animate(element, target) {
clearInterval(element.timeId);
element.timeId = setInterval(function () {
var current = element.offsetLeft;
var step = 10;
step = current < target ? step : -step;
current += step;
if (Math.abs(current - target) > Math.abs(step)) {
element.style.left = current + "px";
} else {
clearInterval(element.timeId);
element.style.left = target + "px";
}
}, 20);
}
</script>
</body>
</html>
无缝轮播图
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<style>
* {
margin: 0;
padding: 0;
}
ul {
list-style: none;
}
img {
vertical-align: top;
}
.box {
width: 300px;
height: 200px;
margin: 100px auto;
background-color: pink;
border: 1px solid red;
position: relative;
overflow: hidden;
}
.box ul li {
float: left;
}
.box ul {
width: 1500px;
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div class="box" id="screen">
<ul>
<li><img src="imagess/01.jpg" alt=""/></li>
<li><img src="imagess/02.jpg" alt=""/></li>
<li><img src="imagess/03.jpg" alt=""/></li>
<li><img src="imagess/04.jpg" alt=""/></li>
<li><img src="imagess/01.jpg" alt=""/></li>
</ul>
</div>
<script src="common.js"></script>
<script>
var current = 0;
function f1() {
var ulObj = document.getElementById("screen").children[0];
current -= 10;
if (current < -1200) {
ulObj.style.left = 0 + "px";
current = 0;
} else {
ulObj.style.left = current + "px";
}
}
var timeId=setInterval(f1, 20);
document.getElementById("screen").onmouseover=function () {
clearInterval(timeId);
};
document.getElementById("screen").onmouseout=function () {
timeId=setInterval(f1, 20);
};
</script>
</body>
</html>
最终版
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/212448fe6966b8d7b29d7c92ae0da7e4.jpeg)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
* {
padding: 0;
margin: 0;
list-style: none;
border: 0;
}
.all {
width: 500px;
height: 200px;
padding: 7px;
border: 1px solid #ccc;
margin: 100px auto;
position: relative;
}
.screen {
width: 500px;
height: 200px;
overflow: hidden;
position: relative;
}
.screen li {
width: 500px;
height: 200px;
overflow: hidden;
float: left;
}
.screen ul {
position: absolute;
left: 0;
top: 0px;
width: 3000px;
}
.all ol {
position: absolute;
right: 10px;
bottom: 10px;
line-height: 20px;
text-align: center;
}
.all ol li {
float: left;
width: 20px;
height: 20px;
background: #fff;
border: 1px solid #ccc;
margin-left: 10px;
cursor: pointer;
}
.all ol li.current {
background: #DB192A;
}
#arr {
display: none;
}
#arr span {
width: 40px;
height: 40px;
position: absolute;
left: 5px;
top: 50%;
margin-top: -20px;
background: #000;
cursor: pointer;
line-height: 40px;
text-align: center;
font-weight: bold;
font-family: '黑体';
font-size: 30px;
color: #fff;
opacity: 0.3;
border: 1px solid #fff;
}
#arr #right {
right: 5px;
left: auto;
}
</style>
</head>
<body>
<div class="all" id='box'>
<div class="screen"><!--相框-->
<ul>
<li><img src="images/1.jpg" width="500" height="200"/></li>
<li><img src="images/2.jpg" width="500" height="200"/></li>
<li><img src="images/3.jpg" width="500" height="200"/></li>
<li><img src="images/4.jpg" width="500" height="200"/></li>
<li><img src="images/5.jpg" width="500" height="200"/></li>
</ul>
<ol>
</ol>
</div>
<div id="arr"><span id="left"><</span><span id="right">></span></div>
</div>
<script>
var box = document.getElementById("box");
var screen = box.children[0];
var imgWidth = screen.offsetWidth;
var ulObj = screen.children[0];
var list = ulObj.children;
var olObj = screen.children[1];
var arr = document.getElementById("arr");
var pic = 0;
for (var i = 0; i < list.length; i++) {
var liObj = document.createElement("li");
olObj.appendChild(liObj);
liObj.innerHTML = (i + 1);
liObj.setAttribute("index", i);
liObj.onmouseover = function () {
for (var j = 0; j < olObj.children.length; j++) {
olObj.children[j].removeAttribute("class");
}
this.className = "current";
pic = this.getAttribute("index");
animate(ulObj, -pic * imgWidth);
};
}
olObj.children[0].className = "current";
ulObj.appendChild(ulObj.children[0].cloneNode(true));
var timeId= setInterval(clickHandle,1000);
box.onmouseover = function () {
arr.style.display = "block";
clearInterval(timeId);
};
box.onmouseout = function () {
arr.style.display = "none";
timeId= setInterval(clickHandle,1000);
};
document.getElementById("right").onclick =clickHandle;
function clickHandle() {
if (pic == list.length - 1) {
pic = 0;
ulObj.style.left = 0 + "px";
}
pic++;
animate(ulObj, -pic * imgWidth);
if (pic == list.length - 1) {
olObj.children[olObj.children.length - 1].className = "";
olObj.children[0].className = "current";
} else {
for (var i = 0; i < olObj.children.length; i++) {
olObj.children[i].removeAttribute("class");
}
olObj.children[pic].className = "current";
}
};
document.getElementById("left").onclick = function () {
if (pic == 0) {
pic = 5;
ulObj.style.left = -pic * imgWidth + "px";
}
pic--;
animate(ulObj, -pic * imgWidth);
for (var i = 0; i < olObj.children.length; i++) {
olObj.children[i].removeAttribute("class");
}
olObj.children[pic].className = "current";
};
function animate(element, target) {
clearInterval(element.timeId);
element.timeId = setInterval(function () {
var current = element.offsetLeft;
var step = 10;
step = current < target ? step : -step;
current += step;
if (Math.abs(current - target) > Math.abs(step)) {
element.style.left = current + "px";
} else {
clearInterval(element.timeId);
element.style.left = target + "px";
}
}, 10);
}
</script>
<script>
</script>
</body>
</html>