当前位置:网站首页>Left and right cases + rotating pictures of small dots + no time
Left and right cases + rotating pictures of small dots + no time
2022-06-12 12:04:00 【Mustang (Mustang)】
effect

Code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
/* *{
margin: 0;
padding: 0;
} */
.carousel /* A large container */
{
width: 960px;
height:320px;
margin: auto;
position: relative;
overflow: hidden;
}
.imgCon /* Figure container */
{
width: 4800px;
height: 320px;
position: absolute;
left: 0;
font-size: 0;
transition: all 2s;/* transition */
}
.imgCon img{ /* Shuffling figure img Size */
width: 960px;
height: 320px;
}
.dot /*ul location */
{
list-style: none;
position: absolute;
bottom: 20px;
left:380px
}
.dot>li{ /*lide Set up */
width: 18px;
height: 18px;
border-radius: 10px;
border: 1px solid red;
background-color: rgba(255,0,0,0);/* background , invisible */
float: left; /* float */
margin-left: 20px;
}
.dot>li:nth-child(1){
background-color: rgba(255,0,0,0.6);
}
.leftBn,.rightBn /* Left and right buttons */
{
position: absolute;
top:140px;
}
.leftBn{ /* Left button */
left:20px;
}
.rightBn{ /* Another button */
right: 20px;
}
</style>
</head>
<body>
<div class="carousel">
<!-- picture , Background image -->
<div class="imgCon">
<img src="./img/a.jpeg">
<img src="./img/b.jpeg">
<img src="./img/c.jpeg">
<img src="./img/d.jpeg">
<img src="./img/e.jpeg">
</div>
<!-- Little dots -->
<ul class="dot">
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
<!-- Left and right buttons -->
<img src="img/left.png" class="leftBn">
<img src="img/right.png" class="rightBn">
</div>
<script>
var imgCon,pre,lis;// Define global variables , The purpose is to share
var position=0; // Given the initial value , According to the order of pictures
// At the beginning, enter the function to perform related operations
init();
function init() {// obtain DOM Elements , Add listening events to the corresponding
imgCon=document.querySelector(".imgCon");// Get the wrapped picture div
lis=document.getElementsByTagName("li");// obtain li Little dots
var leftBn=document.querySelector(".leftBn"); // Get the picture on the left , Button
var rightBn=document.querySelector(".rightBn");// Get the picture on the right , Button
leftBn.addEventListener("click",clickHandler); // Add listening events to the left and right buttons , Click event listening
rightBn.addEventListener("click",clickHandler);// ditto , Left and right
// Little dots li For each li Add click event listening
for(var i=0;i<lis.length;i++){ // Circular dot
lis[i].addEventListener("click",dotClickHandler); // Add click event listening
}
pre=lis[0]; // Set small circle point initially select the first small circle point
}
// Little dots , Click to execute the event
function dotClickHandler(e) { // Little dots li The event of execution
var arr=Array.from(lis); // First convert to an array
position=arr.indexOf(this); // The subscript clicked is the page number
imgMove(); // Click to execute the method
}
// Picture left and right buttons , Click to execute the method
function clickHandler(e) {
// You can print and have a look this
console.log(this);// Information of the currently clicked element ,
if(this.className==="leftBn"){//className Is the attribute to which the current click belongs , The upper line has already been printed , Please check out
position--; //position Used to indicate the number of pictures . Click the left and right buttons to respond , Subtraction operation
if(position<0) position=4; // If you keep clicking the button on the left , It will be reduced to a negative number , So redefine
}else{ // otherwise , That is, what you click is not leftBn, The default here is the right . Of course You can also write accurately
position++; // The left side is added to the fourth page and reset to 0
if(position>4) position=0;
}
imgMove();// Execute the picture in a certain way
}
// How to move pictures
function imgMove() { //
imgCon.style.left=-position*960+"px";// With img Containers for pictures
if(pre){
pre.style.backgroundColor="rgba(0,0,0,0)";
}
pre=lis[position];
pre.style.backgroundColor="rgba(255,0,0,0.6)";
}
//position The initial setting is 0, Click the picture button (leftBn and rightBn) And small dots will change position
</script>
</body>
</html>
Changes

边栏推荐
- Naming specification / annotation specification / logical specification
- 5g NR protocol learning -- ts38.211 downlink channel
- Promise controls the number of concurrent requests
- The second regular match is inconsistent with the first one, and the match in the regular loop is invalid
- Create servlet project
- SSL引入原因及加密步骤
- ARM指令集之数据处理指令寻址方式
- MVC模式、加密、jsonwebtoken
- Load/store memory access instruction of arm instruction set (1)
- LeetCode_二分搜索_中等_162. 寻找峰值
猜你喜欢

Inter class and intra class relations in video classification -- regularization

The second day of QML study

ARM processor mode and register

Node crawler puppeter usage

QML学习 第二天

Ros- resolve error "tf2\u buffer\was not declared in this scope"

Batch load/store instructions of arm instruction set

创建Servlet项目
![[foundation of deep learning] back propagation method (1)](/img/0b/540c1f94712a381cae4d30ed624778.png)
[foundation of deep learning] back propagation method (1)

QT adds a summary of the problems encountered in the QObject class (you want to use signals and slots) and solves them in person. Error: undefined reference to `vtable for xxxxx (your class name)‘
随机推荐
ioremap
How to determine the relationship between home page and search? Relationship between homepage and search
Google Earth engine (GEE) - quick land classification by kmeans clustering (double for loop quick parameter adjustment)
QT添加QObject类(想使用信号和槽)遇到的问题汇总,亲测解决有效error: undefined reference to `vtable for xxxxxx(你的类名)‘
如何确定首页和搜索之间的关系呢?首页与搜索的关系
必杀技--使用FFmpeg命令快速精准剪切视频
TinyMCE series (IV) introduction to common built-in UI components of TinyMCE
PDSCH related
ARM指令集之Load/Store指令寻址方式(一)
Spark common encapsulation classes
for in 与Object.keys()的区别
Load/store instruction addressing mode of arm instruction set (2)
Promise controls the number of concurrent requests
6.6 separate convolution
Blue Bridge Cup 2015 CA provincial competition (filling the pit)
7-5 complex quaternion operation
The first thing with a server
LeetCode 1037. 有效的回旋镖(向量叉乘)
Who moved my package lock
Naming specification / annotation specification / logical specification