当前位置:网站首页>JS rotation chart
JS rotation chart
2022-07-01 04:21:00 【MyDreamingCode】
One 、 Carousel chart style + structure
1. structure ( Left and right arrows 、 Small circle 、 Rotation picture area )
<div class="banner">
<a href="javascript:;" class="arrow_pre arrow"></a>
<a href="javascript:;" class="arrow_next arrow"></a>
<ul class="lunbo">
<li>
<a href="#">
<img src="./uploads/banner1.jpg">
</a>
</li>
<li>
<a href="#">
<img src="./uploads/banner2.jpg">
</a>
</li>
<li>
<a href="#">
<img src="./uploads/banner3.jpg">
</a>
</li>
<li>
<a href="#">
<img src="./uploads/banner4.jpg">
</a>
</li>
</ul>
<ul class="dot"></ul>
</div>2. style
* {
padding: 0;
margin: 0;
}
ul {
list-style: none;
}
.banner {
position: relative;
width: 721px;
height: 455px;
margin: 50px auto;
overflow: hidden;
}
.banner img {
width: 100%;
height: 100%;
}
.arrow {
position: absolute;
top: 50%;
width: 20px;
height: 32px;
transform: translateY(-50%);
z-index: 1;
display: none;
}
.arrow_pre {
left: 0;
background: url('./img/arrow-prev.png') no-repeat;
}
.arrow_next {
right: 0;
background: url('./img/arrow-next.png') no-repeat;
}
.dot {
position: absolute;
left: 50%;
bottom: 10px;
height: 15px;
padding: 3px;
transform: translateX(-50%);
background-color: rgba(0, 0, 0, .3);
}
.dot li {
float: left;
width: 15px;
height: 15px;
margin: 0 5px;
border-radius: 50%;
background-color: #ccc;
cursor: pointer;
}
.dot li.current {
background-color: #fff;
}
.lunbo {
position: absolute;
top: 0;
left: 0;
width: 400%;
}
.lunbo li {
float: left;
}3. Dynamic generation of small circles
var length = document.querySelector('.lunbo').children.length;
var dot = document.querySelector('.dot');
for(var i = 0; i < length; i++) {
var li = document.createElement('li');
dot.appendChild(li);
li.addEventListener('click', function() {
for(var i = 0; i < dot.children.length; i++) {
dot.children[i].className = '';
}
this.className = 'current';
})
}
dot.children[0].className = 'current';Two 、 operation
1. When the mouse passes the carousel , Show left and right arrow buttons ; When leaving the carousel , Hide the left and right arrow buttons .
window.addEventListener('load', function() {
var banner = document.querySelector('.banner');
var arrow_pre = document.querySelector('.arrow_pre');
var arrow_next = document.querySelector('.arrow_next');
banner.addEventListener('mouseenter', function() {
arrow_pre.style.display = 'block';
arrow_next.style.display = 'block';
})
banner.addEventListener('mouseleave', function() {
arrow_pre.style.display = 'none';
arrow_next.style.display = 'none';
})
})2. introduce animate.js Slow motion animation encapsulation function
function animate(obj, destination, callback) {
clearInterval(obj.timer || null);
obj.timer = setInterval(function(){
var step = (destination - obj.offsetLeft) / 10;
step = step > 0 ? Math.ceil(step) : Math.floor(step);
if(obj.offsetLeft == destination) {
if(callback) {
callback();
}
clearInterval(obj.timer);
}
obj.style.left = obj.offsetLeft + step + 'px';
}, 10)
}3. ul The moving formula of the rotation area :dot Reference no. × Picture width
var lunbo = document.querySelector('.lunbo');
var length = document.querySelector('.lunbo').children.length;
var dot = document.querySelector('.dot');
for(var i = 0; i < length; i++) {
var li = document.createElement('li');
li.setAttribute('data-index',i);
dot.appendChild(li);
li.addEventListener('click', function() {
for(var i = 0; i < dot.children.length; i++) {
dot.children[i].className = '';
}
this.className = 'current';
animate(lunbo, -banner.offsetWidth * this.dataset.index);
})
}
dot.children[0].className = 'current';边栏推荐
- Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
- 基于Unet的环路滤波
- Jenkins自动清理构建历史
- 206.反转链表
- Account sharing technology enables the farmers' market and reshapes the efficiency of transaction management services
- Concurrent mode of different performance testing tools
- 京东智能客服言犀意图体系搭建和意图识别技术介绍
- Haskell lightweight threads overhead and use on multicores
- C language games (I) -- guessing games
- 多次跳槽后,月薪等于老同事的年薪
猜你喜欢

“目标检测“+“视觉理解“实现对输入图像的理解

Maixll-Dock 使用方法

Daily question - line 10

Recommend the best product development process in the Internet industry!

Possible problems and solutions of using scroll view to implement slider view

Knowledge supplement: redis' basic data types and corresponding commands
![[human version] Web3 privacy game in the dark forest](/img/89/e16789b7f3892002748aab309c45e6.png)
[human version] Web3 privacy game in the dark forest

slf4j 简单实现

CF1638E colorful operations

Inventory the six second level capabilities of Huawei cloud gaussdb (for redis)
随机推荐
OSPF notes [multiple access, two multicast addresses with OSPF]
ThreeJS开篇
CF1638E colorful operations
Offline installation of Wireshark 2.6.10
206. reverse linked list
Analysis and case of pageobject mode
Rule method: number of effective triangles
[TA frost wolf \u may- hundred talents plan] 1.2.3 MVP matrix operation
What are permissions? What are roles? What are users?
JMeter login failure, extracting login token, and obtaining token problem solving
分账技术赋能农贸市场,重塑交易管理服务效能
采购数智化爆发在即,支出宝'3+2'体系助力企业打造核心竞争优势
Hololens2 development environment building and deploying apps
嵌入式系统开发笔记80:应用Qt Designer进行主界面设计
LeetCode 1400. Construct K palindrome strings
Task04 mathematical statistics
All in one 1086: Jiaogu conjecture
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
Embedded System Development Notes 81: Using Dialog component to design prompt dialog box
离线安装wireshark2.6.10