[英]Adding touch option to a slider
I am working on a price range slider. 我正在研究价格范围滑块。 I am following the jQuery guide and use them as reference.
我正在遵循jQuery指南,并将其用作参考。
My problem is that I can't add dragable behavior on the actual slider. 我的问题是我无法在实际的滑块上添加可拖动行为。 I've researched and have tried to add
jquery.ui.touch-punch.min.js
, however it did not solve my problem. 我已经研究并尝试添加
jquery.ui.touch-punch.min.js
,但是它没有解决我的问题。
Please see below my code: 请在下面查看我的代码:
$(function() { $("#slider-range-min").slider({ range: "min", value: 400, min: 400, max: 2000, slide: function(event, ui) { $("#amount").val("£" + ui.value); } }); $("#amount").val("£" + $("#slider-range-min").slider("value")); $('#slider-range-min').draggable(); });
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script> <script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script> <script src="jquery.ui.touch-punch.min.js"></script> <p> <label for="amount">Maximum price:</label> <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;"> </p> <div id="slider-range-min"></div>
You will need to make sure you're correctly loading the: 您需要确保正确加载了:
<script src="jquery.ui.touch-punch.min.js"></script>
Your current code expects this file to be in the same folder as your HTML page, if it's hosted elsewhere you will need to change the link or use a CDN of some form. 您当前的代码希望该文件与HTML页面位于同一文件夹中,如果该文件位于其他位置,则需要更改链接或使用某种形式的CDN。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.