当前位置:网站首页>JS implementation of web page rotation map
JS implementation of web page rotation map
2022-04-23 06:54:00 【zjLOVEcyj】
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Shuffling figure </title>
<style>
a {
text-decoration: none;
font-size: 30px;
display: none;
z-index: 2;
}
a:nth-child(1) {
position: absolute;
left: 0px;
top: 27px;
}
a:nth-child(2) {
position: absolute;
right: 0px;
top: 27px;
}
ul {
margin: 0;
padding: 0;
}
.focus {
position: relative;
width: 300px;
height: 100px;
overflow: hidden;
}
ul {
position: absolute;
top: 0px;
left: 0px;
width: 400%;
}
ul li {
float: left;
list-style: none;
width: 300px;
height: 100px;
}
ul li:nth-child(1) {
background-color: pink;
}
ul li:nth-child(2) {
background-color: skyblue;
}
ul li:nth-child(3) {
background-color: purple;
}
ul li:nth-child(4) {
background-color: pink;
}
ol {
position: absolute;
left: 106px;
bottom: 11px;
margin: 0;
padding: 0;
}
ol li {
float: left;
list-style: none;
width: 10px;
height: 10px;
border-radius: 50%;
border: 2px solid #000;
margin-left: 5px;
cursor: pointer;
}
.current {
background-color: #fff;
border: 2px solid #fff;
}
</style>
</head>
<body>
<div class="focus">
<a href=""><</a>
<a href="">></a>
<ul>
<li></li>
<li></li>
<li></li>
</ul>
<ol>
</ol>
</div>
<script>
let focus = document.querySelector('.focus')
let left = document.querySelectorAll('a')[0]
let right = document.querySelectorAll('a')[1]
let items = document.querySelectorAll('ul li')
let ol = document.querySelector('ol')
ul = document.querySelector('ul')
// Picture slide animation function
function animate (element, target, callback) {
clearInterval(element.timer)
element.timer = setInterval(() => {
if (element.offsetLeft == target) {
clearInterval(element.timer)
callback && callback()
}
let cur_distance = (target - element.offsetLeft) > 0 ? Math.ceil((target - element.offsetLeft) / 10) : Math.floor((target - element.offsetLeft) / 10)
element.style.left = element.offsetLeft + cur_distance + 'px'
}, 15)
}
for (let i = 0; i < items.length; i++) {
let li = document.createElement('li')
li.setAttribute('index', i)
ol.append(li)
}
ol.children[0].className = 'current'
focus.addEventListener('mouseenter', () => {
left.style.display = 'block'
right.style.display = 'block'
clearInterval(timer)
timer = null
})
focus.addEventListener('mouseleave', () => {
left.style.display = 'none'
right.style.display = 'none'
timer = setInterval(() => {
right.click()
}, 2000)
})
ol.addEventListener('click', (e) => {
if (e.target.tagName === 'OL') return
for (let k of ol.children) {
k.className = ''
}
e.target.className = 'current'
let focusWidth = focus.offsetWidth
let target = -focusWidth * parseInt(e.target.getAttribute('index'))
cur_index = parseInt(e.target.getAttribute('index'))
circle = parseInt(e.target.getAttribute('index'))
animate(ul, target)
})
let first = ul.children[0].cloneNode(true)
ul.append(first)
let cur_index = 0
let circle = 0
let flag = true
right.addEventListener('click', (e) => {
e.preventDefault()
if (flag) {
flag = false
if (cur_index === 3) {
ul.style.left = '0px'
cur_index = 0
}
cur_index += 1
animate(ul, -cur_index * focus.offsetWidth, function () {
flag = true})
circle += 1
if (circle == 3) {
circle = 0
}
for (let k of ol.children) {
k.className = ''
}
ol.children[circle].className = 'current'
}
})
left.addEventListener('click', (e) => {
e.preventDefault()
if (cur_index === 0) {
ul.style.left = '-900px'
cur_index = 3
}
cur_index -= 1
animate(ul, -cur_index * focus.offsetWidth)
circle -= 1
if (circle == -1) {
circle = 2
}
for (let k of ol.children) {
k.className = ''
}
ol.children[circle].className = 'current'
})
// Automatic wheel broadcasting
let timer = setInterval(() => {
right.click()
}, 2000)
</script>
</body>
</html>

版权声明
本文为[zjLOVEcyj]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230555333398.html
边栏推荐
- SQL学习|窗口函数
- postMan 传参总结
- Baidu map coordinates, Google coordinates and Tencent coordinates are mutually transformed
- Concurrent optimization request
- JS手写兼容性事件绑定
- Curry realization of function continuous call calculation and accumulation
- el-date-picker限制选择范围,从当前时间到两个月前
- 模仿扇贝短文阅读页面
- js中entries(),keys(),values() , some(), Object.assign()遍历数组用法
- Unix期末考试总结--针对直系
猜你喜欢
随机推荐
ASP.NET CORE3.1 Identity注册用户后登录失败的解决方案
Sum (if) in MySQL_ Sum (if ()) in MySQL
leetcode刷题之二进制求和
TypeScript(下)
JS实现网页轮播图
Counts the number of occurrences of each character in the string
C# Task.Delay和Thread.Sleep的区别
offset和client获取dom元素位置信息
js查找字符串中出现了三次的字符
Centos8 builds php8 0.3 operating environment
不用登录直接下载PNG图标的一个网站
freeCodeCamp----arithmetic_arranger练习
Jenkins搭建与使用
条形码与二维码的生成
Thinkphp5 -- object (think \ response \ JSON) to array
file_ get_ Two solutions to content accessing SSL errors
浏览器中堆栈内存的底层处理
阅读笔记:FedGNN: Federated Graph Neural Network for Privacy-Preserving Recommendation
The difference between VaR, let and Const
NodeJS 模块之间的使用









