当前位置:网站首页>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
边栏推荐
- Two implementation methods of stack
- ansible基本配置
- TCP RTT measurement tips
- You are using pip version 21.1.2; however, version 22.1.2 is available
- Balanced binary search tree
- St Table + two points
- Binary search tree template
- 华大04a工作模式/低功耗模式
- LINQ query collection class introductory cases Wulin expert class
- 03--- antireflective film
猜你喜欢

Guava中这些Map的骚操作,让我的代码量减少了50%

Servlet详解

The collection of zero code enterprise application cases in various industries was officially released

Flutter 库冲突问题解决

波卡生态发展不设限的奥义——多维解读平行链

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

Detailed installation and use of performance test tool wrk

关于自动控制原理资料更新

The process from troubleshooting to problem solving: the browser suddenly failed to access the web page, error code: 0x80004005, and the final positioning: "when the computer turns on the hotspot, the

60 divine vs Code plug-ins!!
随机推荐
Collective search + drawing creation
The process from troubleshooting to problem solving: the browser suddenly failed to access the web page, error code: 0x80004005, and the final positioning: "when the computer turns on the hotspot, the
Two implementation methods of stack
权限想要细化到按钮,怎么做?
Excel layout
Resolving the conflict problem of the flutter Library
系统测试主要步骤
Flutter: Unsupported value: false/true
Practice of hierarchical management based on kubesphere
Getting started with typescript
Rotate the square array of two-dimensional array clockwise by 90 °
零代码即可将数据可视化应用到企业管理中
CV2 package guide times could not find a version that satisfies the requirement CV2 (from versions: none)
[notes of wuenda] fundamentals of machine learning
[notes of Wu Enda] multivariable linear regression
Development trend and path of SaaS industry in China
性能测试工具wrk安装使用详解
A deep learning model for urban traffic flow prediction with traffic events mined from twitter
The profound meaning of unlimited ecological development in Poka -- Multidimensional Interpretation of parallel chain
KT6368A蓝牙芯片的主从机之前透传功能说明,2.4G跳频自动连接