小编Dab*_*r00的帖子

如何使用纯JavaScript和CSS创建垂直轮播

我正在尝试使用vanilla JavaScript和CSS创建一个垂直轮播.我知道jQuery有一个轮播库但是我想要从头开始构建这个没有外部库的东西.我开始尝试移动顶部图像,然后我计划继续进行下一个图像移动.我卡在第一张图片上.这是我需要你帮助的地方,StackOverflowers.

我的HTML:

<div class="slider vertical" >
    <img class="first opened" src="http://malsup.github.io/images/beach1.jpg">
    <img class="opened" src="http://malsup.github.io/images/beach2.jpg">
    <img src="http://malsup.github.io/images/beach3.jpg">
    <img src="http://malsup.github.io/images/beach4.jpg">
    <img src="http://malsup.github.io/images/beach5.jpg">
    <img src="http://malsup.github.io/images/beach9.jpg">
</div>
<div class="center">
    <button id="prev">? Prev</button>
    <button id="next">? Next</button>
</div>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

var next = document.getElementById('next');
var target = document.querySelector('.first');

next.addEventListener('click', nextImg, false);

function nextImg(){
     if (target.classList.contains('opened')) {
        target.classList.remove('opened');
        target.classList.add('closed');
    } else {
        target.classList.remove('closed');
        target.classList.add('opened');
    }
}
Run Code Online (Sandbox Code Playgroud)

CSS:

div.vertical {
    width: 100px;
}

.slider {
    position: relative;
    overflow: hidden;
    height: 250px;

        -webkit-box-sizing:border-box;
       -moz-box-sizing:border-box;
        -ms-box-sizing:border-box;
            box-sizing:border-box;

    -webkit-transition:-webkit-transform 1.3s ease;
       -moz-transition: …
Run Code Online (Sandbox Code Playgroud)

html javascript css animation carousel

9
推荐指数
1
解决办法
9672
查看次数

标签 统计

animation ×1

carousel ×1

css ×1

html ×1

javascript ×1