当前位置:网站首页>Continue from the previous issue: the remaining two methods of the rotation chart
Continue from the previous issue: the remaining two methods of the rotation chart
2022-07-19 05:12:00 【Create splendid -- hand in hand with you】
The first method of rotation chart :
Simple rotation chart (HTML page ):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>turnPhoto1</title>
<link rel="stylesheet" href="css/turnPhoto1.css">
</head>
<body id="body">
</body>
<script src="js/turnPhoto1.js"></script>
</html>Called as a whole js The content part :
let Maximum = 8;//photoDiv Maximum number of , Can be changed flexibly
function generateElement()// to body add to div
{
let body = window.document.getElementById("body");
let photoDiv;
for (let i = 0; i < Maximum; i++) {
photoDiv = window.document.createElement("div");
// ---------------------------------------------------- Both codes are set class Property value
photoDiv.setAttribute("class", "photo");
// photoDiv.className = "photo";
// ---------------------------------------------------- Both codes are set id Property value
photoDiv.setAttribute("id", i+1+"");
// photoDiv.id=i+1+"";
// ----------------------------------------------------
photoDiv.style.backgroundImage = "url('image/" + (i + 1) + ".jpg')"
body.appendChild(photoDiv);
}
// Put a layer of tulle on the top layer
let veilDiv=window.document.createElement("div");
veilDiv.setAttribute("class","veil");
// veilDiv.className="veil";
body.append(veilDiv);
}
let index = 0;
let photos = window.document.getElementsByClassName("photo");// The rotation chart is manipulated by an array
function turn()// Shuffling figure
{
if (index==photos.length)// After the subscript reaches the length of the array
{
index = 0;// Zero immediately
}
for (let i = 0; i < photos.length; i++) // be-all photoDiv invisible ,for The loop can be changed , But it may not work after the change
{
photos[i].style.display = "none";
}
photos[index].style.display = "block";// Give Way index The point is photoDiv so
index++;
}
generateElement();
setInterval(turn, 2000);// Call the rotation graph function every two seconds css Style part :
body
{
margin: 0;
padding: 0;
background-color: #FDE6E0;
}
.photo
{
width: 100%;
height: 100%;
/*background-image: url("image/1.jpg");*/
background-size:cover;
background-repeat: no-repeat;
position: absolute;
}
.veil
{
width: 100%;
height: 100%;
background-color: #E9EBFE;
opacity:0.3;
position: absolute;
}
The second method of rotation chart :
HTML Page content section :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>turnPhoto2</title>
<link rel="stylesheet" href="css/turnPhoto2.css">
</head>
<body>
<img src="image/8.jpg" id="photo">
<script src="js/turnPhoto2.js"></script>
</body>
</html>
js Call the content section ( Simple type ):
let Maximum = 8;
let index = 1;
let photo =window.document.getElementById("photo");
function turn() {
if (index > Maximum) {
index = 1;
}
// ---------------------------------------------------------------- Set up img Of src attribute , Choose between two ways
// photo.src = "image/" + index + ".jpg";
photo.setAttribute("src","image/"+index+".jpg");
// ----------------------------------------------------------------
index++;
}
setInterval(turn, 2000);
css Style part :
body
{
padding: 0;
margin:0;
background-color: #C7EDCC;
}
#photo
{
width: 100%;
height: 100%;
position: absolute;
top:0px;
left:0px;
}
边栏推荐
- uniapp中使用ucharts图表,饼状图,柱状图,折线图
- Hire the server, and the pytorch environment training yolov5 model tutorial deployed on pycharm professional edition. Server environment installation library file:
- 学习C语言的第6天
- es6新增-数组部分
- Mysql database experiment training 6, data view (detailed)
- Wechat applet status bar
- Elment UI usage
- IDL MODIS 生成查找表
- STL容器——set集合的应用
- 数据分析与数据挖掘实战案例本地房价预测(716):
猜你喜欢
随机推荐
uniapp中使用ucharts图表,饼状图,柱状图,折线图
无重复字符的最长字串
小程序editor富文本编辑使用及rich-text解析富文本
Class object automatic injection attribute operation tool
User login - and create SMS verification code
Interface parameters return encapsulated class result
Teddy Cup title a full version optimization update (4/23)
学习C语言的第四天
IDL调用6S大气校正
使用Echars实现水滴状、环形图、分割图、堆叠、组织架构图、地图轮廓等图表
Internship project 2 - Homepage configuration - my data module
哨兵二号轨道数据下载
小程序云开发 上传图片到云存储
学习C语言第8天
NVIDIA GeForce Experience登录报错:验证程序加载失败,请检查您的浏览器设置,例如广告拦截程序(解决办法)
【C语言_复习_学习第二课】什么是进制?进制之间应该如何转换
数据分析与数据挖掘实战案例本地房价预测(716):
使用js中的(offset,page)实现登录效果
【C语言—零基础第九课】函数中的爱恨情仇
接上期内容:轮播图剩余两种方法









