美文网首页
35、交互式的图片对比控件

35、交互式的图片对比控件

作者: Elevens_regret | 来源:发表于2017-06-07 17:28 被阅读0次

基于input的新type属性range可以实现一种图片对比的特效

// html
<div class="a">
    <div class="b" id="b">
        ![](1.png)
    </div>
    ![](3.jpg)
    <input type="range" id="range" value="0">
</div>

// css
.a{
    width: 1200px;
    height: 720px;
    margin: 100px auto;
    position: relative;
}
.a img{
    display: block;
    height: 100%;
    user-select: none;
}
.b{
    position: absolute;
    width: 50%;
    top: 0;
    bottom: 0;
    left: 0;
    overflow: hidden;
}
#range{
    position: absolute;
    bottom: 10px;
    width: 50%;
    transform: scale(2);
    transform-origin: left bottom;
}

// js
var b = document.getElementById("b");
var input=document.getElementById("range");
b.style.width=input.value+'%';
input.oninput=function () {
    b.style.width=this.value+'%';
}

相关文章

网友评论

      本文标题:35、交互式的图片对比控件

      本文链接:https://www.haomeiwen.com/subject/pnkafxtx.html