首页 > 其他分享 >轮播图

轮播图

时间:2023-04-07 19:34:50浏览次数:38  
标签:className 轮播 next current let imgs prev

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
        <link rel="stylesheet" href="font/iconfont.css">
        <link rel="stylesheet" href="new_file.css">
    </head>
    <body>
        <div class="slideshow">
            <img src="img/1.gif" class="current">
            <img src="img/2.gif" class="next">
            <img src="img/3.gif" >
            <img src="img/4.gif" class="prev">
            <div class="button left">
                <span class="iconfont icon-xiangzuo"></span>
            </div>
            <div class="button right">
                <span class="iconfont icon-xiangyou"></span>
            </div>
        </div>
        <script src="new_file.js"></script>
    </body>
</html>
*{
    margin: 0;
    padding: 0;
}
body{
    height: 100vh;
    background-color: rgb(170, 190, 250);
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
.slideshow{
    position: relative;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
}
img{
    display: block;
    width: 240px;
    height: 320px;
    background-color: white;
    clip-path: circle(120px);
    position: absolute;
    opacity: 0;
    z-index: -1;
    transition: all 0.5s;
}
.current{
    opacity: 1;
    z-index: 99;
    transform: scale(1.5);
}
.prev{
    opacity: 0.5;
    z-index: 10;
    transform: translateX(-100%);
}
.next{
    opacity: 0.5;
    z-index: 10;
    transform: translateX(100%);
}
.button{
    position: absolute;
    z-index: 100;
    cursor: pointer;
    background-color: black;
    color: white;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    text-align: center;
    line-height: 50px;
    opacity: 0.5;
}
.button span{
    font-size: 25px;
}
.button.left{
    transform: translateX(-180px);
}
.button.right{
    transform: translateX(180px);
}
let left = document.querySelector('.left')
let right = document.querySelector('.right')
let imgs = document.querySelectorAll('img')
let prev = 3
let current = 0
let next = 1

console.log(prev,current,next);

left.onclick = ()=>{
    prev = current
    current = next
    next = next + 1
    if (next>3){
        next=0
    }
    console.log(prev,current,next);
    imgs.forEach((img)=>{img.removeAttribute('class')})
    imgs[prev].className='prev'
    imgs[current].className='current'
    imgs[next].className='next'
}

right.onclick = ()=>{
    next = current
    current = prev
    prev = prev - 1
    if (prev<0){
        prev=3
    }
    console.log(prev,current,next);
    imgs.forEach((img)=>{img.removeAttribute('class')})
    imgs[prev].className='prev'
    imgs[current].className='current'
    imgs[next].className='next'
}

标签:className,轮播,next,current,let,imgs,prev
From: https://www.cnblogs.com/duan-rui/p/17297159.html

相关文章

  • 直播平台搭建源码,XBanner设置只显示轮播图
    直播平台搭建源码,XBanner设置只显示轮播图setData()和loadImage()方法同时设置才能生效XBannerbannerView;privateList<BannerItem>bannerItems=newArrayList<>();bannerItems.clear();bannerItems.addAll(bannerItem);bannerView.setData(R.layout.xbanner_custom_layout,......
  • JS轮播图定时播放,鼠标经过轮播图时不停,鼠标离开轮播图时播放速度越来越快
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width=d......
  • js实现文字左右轮播
    <!DOCTYPEhtml><html><head><metacharset="utf-8"><title></title><styletype="text/css">.textDiv{position:relative;......
  • bootstrap之carousel轮播图自定义分页器
    最近要开发一个轮播图的看板页面,试用下bootstrap的轮播图组件,因为分页器的部分需要自定义(文字过长需要放到轮播图区域的外面),使用 Listgroup组件作为轮播图的分页器放在左边。 <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv=......
  • 无缝轮播图2
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equ......
  • 简易轮播图
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><metahttp-equ......
  • 无缝轮播图1
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>Title</title><scriptsrc="../move.js"></script><style>.banner{w......
  • ant design 轮播图左右两边加箭头
    <Carouselautoplayarrows={true}prevArrow={<LeftOutlined/>}nextArrow={<RightOutlined/>}></Carousel>.ant-carousel.slick-prev,.ant-carousel.s......
  • Vue3 + Swiper开发轮播列表组件
    Vue3+Swiper开发轮播列表组件前端开发中,轮播列表的场景并不少见,通常使用Vue+Swiper来实现,上手比较快。安装依赖直接执行npm命令npmiswiper组件编写Html模板......
  • JS+CSS 轮播通知效果
    使用JS+CSS实现一个简单的轮播通知效果图html<div><ulid="notification"><li>通知1</li><li>通知2</li><li>通知3</li><li>通知4</li......