分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

html5拖动滑块

发布时间:2023-09-06 01:21责任编辑:林大明关键词:暂无标签

html5中input有增加type=range。这为拖动滑块提供了很大的便利。下面是他的属性:

<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title>Title</title> ???<style> ???????.main{ position: relative;width: 500px;} ???????#range { ???????????-webkit-appearance: none; ???????????background: #999; ???????????height: 3px; ???????????outline: none; ???????????margin: 0; ???????????width: 500px; ???????} ???????input[type=range]::-webkit-slider-thumb{ ???????????-webkit-appearance: none; ???????????width: 20px; ???????????height: 20px; ???????????border-radius: 50%; ???????????background: red; ???????} ???????p{ ???????????position: absolute; ???????????width: 0px; ???????????height: 3px; ???????????background: green; ???????????top: -2px; ???????????left: 0; ???????} ???????.range{ ???????????position: relative; ???????} ???????.value{ ???????????padding: 10px; ???????????background: #ffebc7; ???????????font-size: 40px; ???????????text-align: center; ???????????margin: 0 auto; ???????} ???</style></head><body><div class="main"> ???<div class="value"></div> ???<div class="range"> ???????<input type="range" max="10" min="0" id="range" step="0.1" value="0"> ???????<p></p> ???</div></div></body><script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script><script> ???$(".value").html("0") ???var rangeSwitch=function () { ???????var x=$("#range").val(); ???????$("p").css({"width":(x/10)*500*0.96})//乘的0.96是因为要不然绿色的颜色会有部分盖住滑动按钮(500-20)/500=0.96; ???????$(".value").html(x) ???} ???$("#range").on("input",rangeSwitch)</script></html>

html5拖动滑块

原文地址:http://www.cnblogs.com/yuanzhiguo/p/7766063.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved