<! DOCTYPE html>
<meta charset= "UTF-8" >
<title> New Carousel Map </title>
<link rel= "stylesheet" href= "Index.css" >
*{
margin:0px;
padding:0px;
}
. lunbo{
width:1000px;
height:400px;
BORDER:2PX solid black;
margin:20px Auto;
position:relative;
Overflow:hidden;
}
. nav-bar{
width:90px;
height:20px;
/*background-color:pink;*/
Text-align:center;
Position:absolute;
bottom:20px;
right:20px;
Z-index:1;
}
. Nav-bar. nav-span{
width:20px;
height:20px;
Display:inline-block;
Background-color:black;
border-radius:10px;
}
. Nav-bar. nav-span.selected{
Background-color:white;
}
/* This three-module carrier */
. nav-father{
width:3000px;
height:400px;
/*background-color:red;*/
Transition:all 2s;
}
. nav-child{
width:1000px;
height:400px;
Float:left;
}
<body>
<!--1. Create a new Carousel div---
<div class= "Lunbo" >
<div class= "Nav-bar" >
<span class= "Nav-span selected" Data-num = "0px" ></span>
<span class= "Nav-span" data-num = " -1000px" ></span>
<span class= "Nav-span" data-num = " -2000px" ></span>
</div>
<!--small page carrier---
<div class= "Nav-father" >
<div class= "Nav-child" style= "Background-color:pink;" ></div>
<div class= "Nav-child" style= "Background-color:skyblue;" ></div>
<div class= "Nav-child" style= "Background-color:orange;" ></div>
</div>
</div>
<script>
function Time () {
Each time you get the current selected, let the next label be set to selected
var selected = Document.queryselector (". selected");
Selected.classname = "Nav-span";
Make the next sibling node into selected
if (selected.nextelementsibling! = null) {
Selected.nextElementSibling.className = "Nav-span selected";
Get Selected.nextelementsibling.data-num
var number = Selected.nextElementSibling.getAttribute ("Data-num");
var father = Document.queryselector (". Nav-father");
Father.style.transform = "translate (" + number+ ", 0px)";
}else{
Selected.parentNode.firstElementChild.className = "Nav-span selected";
Get Selected.nextelementsibling.data-num
var number = Selected.parentNode.firstElementChild.getAttribute ("Data-num");
var father = Document.queryselector (". Nav-father");
Father.style.transform = "translate (" + number+ ", 0px)";
}
}
Timer
(1) Call once every 4 seconds
(2) Get the current selected at the first time
var timer = setinterval (time,4000);
Click
(1) Find all the Nav-span
var spanarrays = Document.queryselectorall (". Nav-span");
(2) Set Click events
for (var i = 0;i< spanarrays.length;i++) {
Spanarrays[i].onclick=function () {
Clearinterval (timer);
(3) Make yourself into a selected and let the others become normal
for (Var j =0;j<spanarrays.length;j++) {
Revert to normal
Spanarrays[j].classname = "Nav-span";
}
(4) Set the click to Nav-span selected
This.classname = "Nav-span selected";
Change Picture ... It means transform-translate.
Find Nav-father
var father = Document.queryselector (". Nav-father");
Panning values
var number = This.getattribute ("Data-num");
Father.style.transform = "translate (" + number+ ", 0px)";
Timer = setinterval (time,4000);
}
}
</script>
Mobile Carousel Diagram