扫码关注官方订阅号
如何添加一个水平拖动条,通过拖动条来控制内部两个p的宽度,恳请大神指点
认证0级讲师
不知道你要的是不是这种:
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> <style> p.container { width: 504px; height: 400px; border: 1px solid gray; } p.left { width: 250px; height: 398px; border: 1px solid gray; float: left; } p.right { width: 250px; height: 398px; border: 1px solid gray; float: left; } </style> </head> <body> <p class="container"> <p class="left"></p> <p class="right"></p> </p> <input type="range" id="leftBar" value="250" max="250" min="0"></input> <input type="range" id="rightBar" value="250" max="250" min="0"></input> <script> var leftp = document.getElementsByTagName("p")[1]; var rightp = document.getElementsByTagName("p")[2]; var leftBar = document.getElementsByTagName("input")[0]; var rightBar = document.getElementsByTagName("input")[1]; rightBar.onmousemove = function() { var val = rightBar.value; rightp.style.width = val + "px"; }; leftBar.onmousemove = function() { var val = leftBar.value; leftp.style.width = val + "px"; }; </script> </body> </html>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
不知道你要的是不是这种:
<!DOCTYPE html>