当前位置:网站首页>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();
}
})
}边栏推荐
- Cnopendata geographical distribution data of religious places in China
- Linux server development, MySQL process control statement
- Installing postgresql11 database under centos7
- Qt学习26 布局管理综合实例
- pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
- 即刻报名|飞桨黑客马拉松第三期等你挑战
- JSON data flattening pd json_ normalize
- 大视频文件的缓冲播放原理以及实现
- Leanote private cloud note building
- Solution: could not find kf5 (missing: coreaddons dbusaddons doctools xmlgui)
猜你喜欢

Figure out the working principle of gpt3

Kbu1510-asemi power supply special 15A rectifier bridge kbu1510

The charm of SQL optimization! From 30248s to 0.001s

2022 simulated examination question bank and online simulated examination of tea master (primary) examination questions

2022 tea master (intermediate) examination questions and mock examination

The configuration that needs to be modified when switching between high and low versions of MySQL 5-8 (take aicode as an example here)

QT learning 28 toolbar in the main window

2022 welder (elementary) judgment questions and online simulation examination

IO stream file
![[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替](/img/e3/cceede6babae3c8a24336c81d98aa7.jpg)
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
随机推荐
Linux server development, MySQL index principle and optimization
Chip information website Yite Chuangxin
Live online system source code, using valueanimator to achieve view zoom in and out animation effect
PHP exports millions of data
【数字IC验证快速入门】17、SystemVerilog学习之基本语法4(随机化Randomization)
Hands on deep learning (IV) -- convolutional neural network CNN
misc ez_usb
Linux server development, MySQL stored procedures, functions and triggers
Idea add class annotation template and method template
[Matlab] Simulink 自定义函数中的矩阵乘法工作不正常时可以使用模块库中的矩阵乘法模块代替
Codeforces Global Round 19
dash plotly
2022 tea master (intermediate) examination questions and mock examination
pytest+allure+jenkins安装问题:pytest: error: unrecognized arguments: --alluredir
LeetCode 40:组合总和 II
Paddlepaddle 29 dynamically modify the network structure without model definition code (relu changes to prelu, conv2d changes to conv3d, 2D semantic segmentation model changes to 3D semantic segmentat
大视频文件的缓冲播放原理以及实现
3D reconstruction - stereo correction
Gslx680 touch screen driver source code analysis (gslx680. C)
【VHDL 并行语句执行】