繁体   English   中英

如何使移动响应垂直范围slider

[英]How to make mobile responsive vertical range slider

我已经做了一个范围 slider position 到垂直。 但它没有响应。 我签入了 chrome 默认移动设备。 调整范围 slider 时,它将滚动页面

我在这里添加了我的代码。

 .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不会影响其父元素或任何其他元素的大小或 position。 绝对没有办法改变转换如何工作的事实。 所以在父级添加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>

您已将水平 slider 转换为垂直,这将不起作用,因此您可以使用垂直 slider 仅检查片段。

 let app = (() => { function updateSlider(element) { if (element) { let parent = element.parentElement, lastValue = parent.getAttribute('data-slider-value'); if (lastValue === element.value) { return; // No value change, no need to update then } parent.setAttribute('data-slider-value', element.value); let $thumb = parent.querySelector('.range-slider__thumb'), $bar = parent.querySelector('.range-slider__bar'), pct = element.value * ((parent.clientHeight - $thumb.clientHeight) / parent.clientHeight); $thumb.style.bottom = `${pct}%`; $bar.style.height = `calc(${pct}% + ${$thumb.clientHeight/2}px)`; $thumb.textContent = `${element.value}%`; } } return { updateSlider: updateSlider }; })(); (function initAndSetupTheSliders() { const inputs = [].slice.call(document.querySelectorAll('.range-slider input')); inputs.forEach(input => input.setAttribute('value', '50')); inputs.forEach(input => app.updateSlider(input)); // Cross-browser support where value changes instantly as you drag the handle, therefore two event types. inputs.forEach(input => input.addEventListener('input', element => app.updateSlider(input))); inputs.forEach(input => input.addEventListener('change', element => app.updateSlider(input))); })();
 *, *:before, *:after { box-sizing: border-box; } html, body { height: 100%; } body { margin: 0; background: #3D3D4A; color: white; font-family: sans-serif; }.info { position: absolute; top: 0; left: 0; padding: 10px; opacity: 0.5; }.container { position: relative; display: inline-block; padding-top: 40px; }.range-slider { display: inline-block; width: 40px; position: relative; text-align: center; max-height: 100%; }.range-slider:before { position: absolute; top: -2em; left: 0.5em; content: attr(data-slider-value) '%'; color: white; font-size: 90%; }.range-slider__thumb { position: absolute; left: 5px; width: 30px; height: 30px; line-height: 30px; background: white; color: #777; font-size: 50%; box-shadow: 0 0 0 4px #3D3D4A; border-radius: 50%; pointer-events: none; }.range-slider__bar { left: 16px; bottom: 0; position: absolute; background: linear-gradient(dodgerblue, blue); pointer-events: none; width: 8px; border-radius: 10px; }.range-slider input[type=range][orient=vertical] { position: relative; margin: 0; height: calc(100vh - 50px); width: 100%; display: inline-block; position: relative; writing-mode: bt-lr; -webkit-appearance: slider-vertical; }.range-slider input[type=range][orient=vertical]::-webkit-slider-runnable-track, .range-slider input[type=range][orient=vertical]::-webkit-slider-thumb { -webkit-appearance: none; }.range-slider input[type=range][orient=vertical]::-webkit-slider-runnable-track { border: none; background: #343440; width: 8px; border-color: #343440; border-radius: 10px; box-shadow: 0 0 0 2px #3D3D4A; }.range-slider input[type=range][orient=vertical]::-moz-range-track { border: none; background: #343440; width: 8px; border-color: #343440; border-radius: 10px; box-shadow: 0 0 0 2px #3D3D4A; }.range-slider input[type=range][orient=vertical]::-ms-track { border: none; background: #343440; width: 8px; border-color: #343440; border-radius: 10px; box-shadow: 0 0 0 2px #3D3D4A; color: transparent; height: 100%; }.range-slider input[type=range][orient=vertical]::-ms-fill-lower, .range-slider input[type=range][orient=vertical]::-ms-fill-upper, .range-slider input[type=range][orient=vertical]::-ms-tooltip { display: none; }.range-slider input[type=range][orient=vertical]::-webkit-slider-thumb { width: 30px; height: 30px; opacity: 0; }.range-slider input[type=range][orient=vertical]::-moz-range-thumb { width: 30px; height: 30px; opacity: 0; }.range-slider input[type=range][orient=vertical]::-ms-thumb { width: 30px; height: 30px; opacity: 0; }
 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="container"> <div class="range-slider"> <input type="range" orient="vertical" min="0" max="100" /> <div class="range-slider__bar"></div> <div class="range-slider__thumb"></div> </div> </div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM