当前位置:网站首页>Development of live broadcast software app, and automatic left-right sliding rotation chart advertising
Development of live broadcast software app, and automatic left-right sliding rotation chart advertising
2022-06-24 22:12:00 【Yunbao network technology】
Live Software app Development , Auto slide left and right carousel advertising
1、 css part :
* {
margin:0;
padding:0;
box-sizing:border-box;
/* overflow: hidden; */
}
.app{
position: absolute;
top:50%;
left:50%;
transform: translate(-50%,-50%);
height: 280px;
width: 520px;
overflow: hidden;
border-radius: 8px;
/* display: block; */
}
.app:hover .iconfont{
display:block;
}
.wrapper{
z-index:1;
display: block;
position: absolute;
list-style:none;
/* Process blank folds */
font-size: 0;
}
.liWrapper{
display:inline-block;
}
.iconfont {
position:absolute;
z-index:2;
font-size:24px;
height:24px;
color: blanchedalmond;
background-color: rgba(0,0,0,0.3);
cursor:pointer;
display:none;
}
.icon-arrow-left{
top:50%;
left:-5px;
border-radius: 0 12px 12px 0;
transform:translateY(-50%);
}
.icon-arrow-right{
top:50%;
right:-5px;
border-radius: 11px 0 0 11px;
transform:translateY(-50%);
}
.dot {
z-index:2;
position:absolute;
bottom:15px;
left:50%;
transform: translateX(-50%);
background-color: rgba(255,255,255,.3);
border-radius: 6px;
font-size: 0;
}
.dot span {
display: inline-block;
width: 8px;
height: 8px;
margin: 3px;
border-radius: 4px;
background-color: #fff;
}
.dot-active {
background-color: #ff5500!important;
}
2、 js part :
let perWidth = 520; // The width of a picture
let wrapper = document.querySelector('.wrapper');
let app = document.querySelector('.app');
let liWrapper = document.querySelectorAll('.liWrapper');
let dots = document.querySelector('.dot').children;
let preTime = 0; // Last moment , Processing anti shake
wrapper.style.width = perWidth * liWrapper.length + 'px'; // Get and set the total width of the picture container
// Which picture is it now
let index = 1;
// Timer logo
let timer;
// wrapper initialization
function swiperInit() {
wrapper.style.left = '-' + perWidth * index + 'px';
}
// Rotate left
function leftMoveSwiper() {
index ++;
wrapper.style.left = '-' + perWidth * index + 'px';
wrapper.style.transition = 'left 1s';
if(index >= liWrapper.length - 1) {
setTimeout(() => {
index = 1;
wrapper.style.transition = 'none';
wrapper.style.left = '-' + perWidth * index + 'px';
setDotColor();
},1000)
}
setDotColor();
}
// Shift the rotation chart to the right
function rightMoveSwiper() {
index --;
wrapper.style.left = '-' + perWidth * index + 'px';
wrapper.style.transition = 'left 1s';
if(index <= 0) {
setTimeout(() => {
index = 5;
wrapper.style.transition = 'none';
wrapper.style.left = '-' + perWidth * index + 'px';
},1000)
}
setDotColor();
}
// Auto play
function autoplaySwiper() {
timer = setInterval(() => {
leftMoveSwiper();
},2000);
}
// Event binding
function handleBind(){
// Use event delegation , Bind the click event to the arrow
app.addEventListener('click',function(e){
if(e.target.classList.contains('icon-arrow-left')) {
throttle(rightMoveSwiper,1000);
} else if(e.target.classList.contains('icon-arrow-right')) {
throttle(leftMoveSwiper,1000);
}
});
// The mouse enters to pause the automatic rotation
app.addEventListener('mouseenter',function(){
clearInterval(timer);
});
// The mouse leaves and continues to rotate automatically
app.addEventListener('mouseleave',function(){
autoplaySwiper();
})
}
// Anti shake processing
function throttle(fn,delay) {
let now = Date.now();
if(now - preTime >= delay) {
fn();
preTime = now;
}
}
// dot color setting
function setDotColor() {
for (let i = 0; i < dots.length; i++) {
if(index === i + 1){
dots[i].classList.add('dot-active');
} else {
dots[i].classList.remove('dot-active')
}
if(index === dots.length + 1) {
dots[0].classList.add('dot-active');
} else if(index === 0) {
dots[dots.length - 1].classList.add('dot-active');
}
}
}
// Click the origin to switch the rotation chart
function pointDotChangePic(){
for (let i = 0; i < dots.length; i++) {
dots[i].addEventListener('click',function(){
index = i;
leftMoveSwiper();
})
}
}
// Initialize settings
function init(){
swiperInit();
autoplaySwiper();
handleBind();
setDotColor();
pointDotChangePic();
}
init();
That's all Live Software app Development , Auto slide left and right carousel advertising , More content welcome to follow the article
边栏推荐
- How to extract dates from web pages?
- Graduation design of phase 6 of the construction practice camp
- EasyBypass
- 基于kruskal的最小生成树
- 嵌入式开发:技巧和窍门——干净地从引导加载程序跳转到应用程序代码
- Servlet详解
- St Table + two points
- 华大04a工作模式/低功耗模式
- How to achieve energy conservation and environmental protection of full-color outdoor LED display
- 是真干不过00后,给我卷的崩溃,想离职了...
猜你喜欢

Several classes of manual transactions

PyCharm 中出现Cannot find reference ‘imread‘ in ‘__init__.py‘

60 divine vs Code plug-ins!!

How to extract dates from web pages?

leetcode:515. 在每个树行中找最大值【无脑bfs】

Binary search tree template

Xinlou: Huawei's seven-year building journey of sports health

专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?

socket done

Shutter precautions for using typedef
随机推荐
Minimum spanning tree based on Kruskal
02--- impossible phenomenon of longitudinal wave
Stl+ tree
leetcode:45. Jumping game II [classic greed]
You are using pip version 21.1.2; however, version 22.1.2 is available
华大04a工作模式/低功耗模式
专科出身,2年进苏宁,5年跳阿里,论我是怎么快速晋升的?
You are using pip version 21.1.2; however, version 22.1.2 is available
leetcode_ one thousand three hundred and sixty-five
Yida technology signed a contract with seven wolves to help the digital transformation of "Chinese men's wear leader"
Two implementation methods of stack
ansible基本配置
为什么有的程序员能力一般却能拿到好offer?
Flutter: Unsupported value: false/true
心楼:华为运动健康的七年筑造之旅
Several classes of manual transactions
Maximum flow problem
Xinlou: Huawei's seven-year building journey of sports health
降低pip到指定版本(通过cmp升级pip,在降低到原来版本)
Junior college background, 2 years in Suning, 5 years in Ali. How can I get promoted quickly?