序文
- 最近Douyinで「Choose Love」というゲームを見ました.この人が手動でドラッグしているのを見るのはとても面白かったです.フロントエンドで実現できるのではないかと思ったので,学び、学ぶことができます.最終的な効果はそれほどではありませんが. gif画像のように、それはまだ実現していますね...
具体原理
resize
属性に表示される小さなドラッグ バーを使用します
::-webkit-scrollbar
ドラッグ領域の幅と高さの設定と組み合わせると、opacity:0
ドラッグ領域は div 全体をカバーできます。
特定の効果とコード
効果
- オンラインデモ
- https://codepen.io/superbiubiuman/pen/oNMQxKz
- 写真
コード
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>拖拽照片</title>
<style>
*{
margin: 0;
padding: 0;
}
body,html{
width: 100%;
height: 100%;
}
.pic{
width: 100%;
height: 100%;
box-sizing: border-box;
padding: 16px 6px 0 6px;
background: black;
}
.content{
width: 100%;
box-sizing: border-box;
background: red;
display: flex;
flex-direction: row;
flex-wrap: nowrap;
overflow: hidden;
}
.right,
.left
{
background-position: left;
background-size: 100vw auto;
background-repeat: no-repeat;
}
.left{
background-image: url(https://dreamos.oss-cn-beijing.aliyuncs.com/gitblog/202302012011639.jpg);
position: relative;
}
.right{
background-image: url(https://dreamos.oss-cn-beijing.aliyuncs.com/gitblog/202302012011607.jpg);
flex: 1;
}
.drag{
border-right: 1px solid blue;
width: 50vw;
height: 80vh;
cursor: ew-resize;
resize: horizontal;
overflow: scroll;
opacity: 0;
}
.drag::-webkit-scrollbar{
width: 50vw;
height: 80vh;
}
.bottom{
height: 10%;
box-sizing: border-box;
}
</style>
</head>
<body>
<div class="pic">
<div class="content">
<div class="left">
<div class="drag"></div>
</div>
<div class="right"></div>
</div>
<div class="bottom"></div>
</div>
</body>
</html>
参照リンクと記事