javascript - 如何制作移动响应式垂直范围滑块
问题描述
我已经将范围滑块位置设置为垂直。但它没有响应。我签入了 chrome 默认移动设备。调整范围滑块时,它将滚动页面
我在这里添加了我的代码。
.slido{
-webkit-appearance: none;
width: 100%;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
-webkit-transform: rotate(90deg);
}
.slido::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
<input type="range" class="slido" min="1" max="100" step="1">
解决方案
仅transform
在元素上使用根本不会影响其父元素或任何其他元素的大小或位置。绝对没有办法改变转换如何工作的事实。所以添加div
父级(可以处理旋转溢出)是一种解决方案。
代码更新:
.slido {
-webkit-appearance: none;
width: 100vh;
height: 15px;
border-radius: 5px;
background: #d3d3d3;
outline: none;
opacity: 0.7;
-webkit-transition: .2s;
transition: opacity .2s;
transform: rotate(90deg);
}
.slido::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
width: 25px;
height: 25px;
border-radius: 50%;
background: #4CAF50;
cursor: pointer;
}
.rotation-wrapper-outer {
display: table;
}
.rotation-wrapper-inner {
padding: 50% 0;
height: 0;
}
.element-to-rotate {
display: block;
transform-origin: top left;
/* Note: for a CLOCKWISE rotation, use the commented-out
transform instead of this one. */
transform: rotate(-90deg) translate(-100%);
/* transform: rotate(90deg) translate(0, -100%); */
margin-top: -50%;
/* Not vital, but possibly a good idea if the element you're rotating contains
text and you want a single long vertical line of text and the pre-rotation
width of your element is small enough that the text wraps: */
white-space: nowrap;
}
<div id="container">
<div class="rotation-wrapper-outer">
<div class="rotation-wrapper-inner">
<input type="range" class="slido" min="1" max="100" step="1">
</div>
</div>
</div>
推荐阅读
- xcode - 使用新的 Apple 构建系统 (xcbuild) 时缺少 productTypeIdentifier 错误
- php - 在类似的测试中,PHP 7.4.8 比相同的 c++ 程序快 5.6 倍 (g++ 4.8.5)
- biztalk - 将消息传输到客户发送端口时 BizTalk AS2 发送端口错误
- android - 如何在 BOTH 表上获得一对多房间 Android 条件?
- javascript - 从 Promise 或 async / await 返回的值的数据类型
- android - 谷歌登录不适用于使用电容器生成的 ionic android 移动应用程序 - 抛出异常为 10
- reactjs - VS2019如何重启在本地构建时自动启动的npm
- android - 如何在对话框选择器中显示选定的日期?
- python-3.x - 得到 TypeError: Expected int32, got None of type 'NoneType' 相反
- .net - 在 .NET 正则表达式中,将零宽度正前瞻断言与其他搜索词结合起来