当前位置:网站首页>Roulette chart 2 - writing of roulette chart code
Roulette chart 2 - writing of roulette chart code
2022-07-07 07:59:00 【Code machine - Ying】
<div class="banner"> </div>
<script src="./02move.js"></script>
<script>
let oBanner = document.querySelector('.banner');
const arr = [
{ id: 1, width: 500, height: 333, url: '1.jpg' },
{ id: 2, width: 500, height: 333, url: '2.jpg' },
{ id: 3, width: 500, height: 333, url: '3.jpg' },
{ id: 4, width: 500, height: 333, url: '4.jpg' },
{ id: 5, width: 500, height: 333, url: '5.jpg' }
];
let index = 1;
let oUl;
let oOl;
let oDiv;
let oUllis;
let oOllis;
let liWidth;
let time;
let res = true;
// Call the auto generate page function
setPage();
autoLoop();
mouseMove();
setClick();
hidden();
// Dynamically generate pages
function setPage() {
oUl = document.createElement('ul');
oOl = document.createElement('ol');
oDiv = document.createElement('div');
let oUlLiStr = '';
let oOlLiStr = '';
arr.forEach(function (item, key) {
oUlLiStr += `<li><img src="./images/${item.url}" alt=""></li>`;
oOlLiStr += key === 0 ? `<li class="active" num=${key} name="olli"></li>` : `<li num=${key} name='olli'></li>`
})
oUl.innerHTML = oUlLiStr;
oOl.innerHTML = oOlLiStr;
oDiv.innerHTML = `<a href="Javascript:;" name="left"><</a><a href="Javascript:;" name="right">></a>`;
oBanner.appendChild(oUl);
oBanner.appendChild(oOl);
oBanner.appendChild(oDiv);
oUllis = oUl.querySelectorAll('li');
oOllis = oOl.querySelectorAll('li');
liWidth = oUllis[0].offsetWidth;
const oFirstClone = oUllis[0].cloneNode(true);
const oLastClone = oUllis[arr.length - 1].cloneNode(true);
oUl.appendChild(oFirstClone);
oUl.insertBefore(oLastClone, oUllis[0]);
oUl.style.width = (arr.length + 2) * liWidth + 'px';
oUl.style.left = -liWidth + 'px'
}
// Auto carousel function
function autoLoop() {
time = setInterval(function () {
// Prevent clicking too fast
if (res) {
res = false;
}
else {
return;
}
index++;
setFocusStyle();
move(oUl, { left: -liWidth * index }, loopEnd)
}, 3000)
}
// At the end of the rotation function , Called function
function loopEnd() {
if (index === arr.length + 2 - 1) {
index = 1;
}else if(index===0){
index=arr.length;
}
oUl.style.left = -liWidth * index + 'px';
res = true;
}
// Change of focus style
function setFocusStyle() {
oOllis.forEach(function (item, key) {
item.classList.remove('active');
})
if (index === arr.length + 2 - 1) {
oOllis[0].classList.add('active');
}
else if (index === 0) {
oOllis[arr.length - 1].classList.add('active');
}
else {
oOllis[index - 1].classList.add('active')
}
}
// Mouse in and out
function mouseMove() {
oBanner.addEventListener('mouseenter', function () {
clearInterval(time);
});
oBanner.addEventListener('mouseleave', function () {
autoLoop();
})
}
// Add click event
function setClick() {
oBanner.addEventListener("click", function (e) {
if (e.target.getAttribute('name') === 'left') {
if (res) {
res = false;
} else {
return;
}
index--;
setFocusStyle();
move(oUl, { left: -index * liWidth }, loopEnd);
}
else if (e.target.getAttribute('name') === 'right') {
if (res) {
res = false;
} else {
return;
}
index++;
setFocusStyle();
move(oUl, { left: -index * liWidth }, loopEnd);
}
else if (e.target.getAttribute('name') === 'olli') {
if (res) {
res = false;
} else {
return;
}
index = Number(e.target.getAttribute('num'))+1;
setFocusStyle();
move(oUl, { left: -index * liWidth }, loopEnd);
}
})
}
//
function hidden(){
// to documnent Add browser display status monitoring
document.addEventListener('visibilitychange',function(){
// If the status displayed by the browser is hidden
if(document.visibilityState==='hidden'){
// Prove that the current browser hide is minimized
// Clear timer
clearInterval(time);
}
// If the browser displays a status that describes visible
else if(document.visibilityState==='visible'){
// Prove that the current browser displays
// Call the auto rotation function again
autoLoop();
}
})
}边栏推荐
- Idea add class annotation template and method template
- Common validation comments
- C语言二叉树与建堆
- Explore Cassandra's decentralized distributed architecture
- 大视频文件的缓冲播放原理以及实现
- Gslx680 touch screen driver source code analysis (gslx680. C)
- 【obs】win-capture需要winrt
- 芯片 设计资料下载
- 图解GPT3的工作原理
- Why should we understand the trend of spot gold?
猜你喜欢

JSON data flattening pd json_ normalize

nacos
![[webrtc] M98 screen and window acquisition](/img/b1/1ca13b6d3fdbf18ff5205ed5584eef.png)
[webrtc] M98 screen and window acquisition

2022年茶艺师(中级)考试试题及模拟考试

Resource create package method

解决问题:Unable to connect to Redis

Wechat applet data binding multiple data

mysql多列索引(组合索引)特点和使用场景

Linux server development, MySQL transaction principle analysis

Numbers that appear only once
随机推荐
These five fishing artifacts are too hot! Programmer: I know, delete it quickly!
Qt学习26 布局管理综合实例
Shell 脚本的替换功能实现
Wechat applet data binding multiple data
CTF daily question day43 rsa5
Zhilian + AV, AITO asked M7 to do more than ideal one
【webrtc】m98 screen和window采集
【VHDL 并行语句执行】
Linux server development, redis source code storage principle and data model
探索干货篇!Apifox 建设思路
Most elements
Redis technology leak detection and filling (II) - expired deletion strategy
芯片 設計資料下載
Linux server development, MySQL process control statement
Binary tree and heap building in C language
The principle and implementation of buffer playback of large video files
2022年全国最新消防设施操作员(初级消防设施操作员)模拟题及答案
2022制冷与空调设备运行操作复训题库及答案
Linux server development, redis protocol and asynchronous mode
[2022 actf] Web Topic recurrence