当前位置:网站首页>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
边栏推荐
- Datakit agent realizes unified data aggregation in LAN
- “阿里健康”们的逻辑早就变了
- The collection of zero code enterprise application cases in various industries was officially released
- 机器学习:梯度下降法
- 一个女孩子居然做了十年硬件。。。
- Mysql 通过表明获取字段以及注释
- I really want to send a bunch of flowers
- Object.defineProperty和Reflect.defineProperty的容错问题
- Graduation design of phase 6 of the construction practice camp
- MySQL gets fields and comments by indicating
猜你喜欢

Rotate the square array of two-dimensional array clockwise by 90 °

好想送对象一束花呀

Machine learning: linear regression

干货丨产品的可行性分析要从哪几个方面入手?

The logic of "Ali health" has long changed

理想L9,智能座舱新潮流

性能测试工具wrk安装使用详解

How to achieve energy conservation and environmental protection of full-color outdoor LED display

是真干不过00后,给我卷的崩溃,想离职了...

cv2导包时报Could not find a version that satisfies the requirement cv2 (from versions: none)
随机推荐
linq查询集合类入门 案例武林高手类
解决dataframe报错ValueError: Cannot take a larger sample than population when ‘replace=False‘
代理模式详解
That is to say, "live broadcast" is launched! One stop live broadcast service with full link upgrade
Servlet详解
DP problem set
CV2 package guide times could not find a version that satisfies the requirement CV2 (from versions: none)
Cannot find reference 'imread' in 'appears in pycharm__ init__. py‘
Filtered data analysis
DAO 中常见的投票治理方式
关于自动控制原理资料更新
降低pip到指定版本(通过PyCharm升级pip,在降低到原来版本)
Shutter precautions for using typedef
leetcode:55. Jumping game [classic greed]
Collapse code using region
华大04a工作模式/低功耗模式
Double linked list implementation
无心剑汉英双语诗003. 《书海》
leetcode:515. 在每个树行中找最大值【无脑bfs】
Principle and application of queue implementation