jQuery UI Slider: Setting Default Values, Input Fields, and Popup for Handle Selection
To set the starting and ending values of the price slider to 0 and 2000 respectively, you can modify the slider function inside the code as follows:\n\njavascript\n$(function() {\n $("#slider-range").slider({\n range: true,\n min: 0,\n max: 2000, // Set the max value to 2000\n values: [0, 2000], // Set the values to [0, 2000]\n slide: function(event, ui) {\n $("#amount").html("$" + ui.values[0] + " - $" + ui.values[1]);\n $("#min").val(ui.values[0]);\n $("#max").val(ui.values[1]);\n }\n });\n $("#amount").html(\n "$" +\n $("#slider-range").slider("values", 0) +\n " - $" +\n $("#slider-range").slider("values", 1)\n );\n});\n\n\nTo add default values to the input fields and enable a popup to write numbers, you can use the following code:\n\njavascript\n$(function() {\n $("#slider-range").slider({\n range: true,\n min: 0,\n max: 2000,\n values: [0, 2000],\n slide: function(event, ui) {\n $("#amount").html("$" + ui.values[0] + " - $" + ui.values[1]);\n $("#min").val(ui.values[0]);\n $("#max").val(ui.values[1]);\n }\n });\n\n // Set initial input field values\n $("#min").val($("#slider-range").slider("values", 0));\n $("#max").val($("#slider-range").slider("values", 1));\n\n // Add popup to handle selector\n $("#slider-range .ui-slider-handle")\n .each(function() {\n $(this).attr("data-value", $(this).slider("value"));\n })\n .on("mousedown", function() {\n var handle = $(this);\n var popup = $("<div class='popup'></div>").appendTo(handle);\n $("<input type='number' class='popup-input'>")\n .appendTo(popup)\n .on("change", function() {\n handle.slider("value", $(this).val());\n handle.attr("data-value", $(this).val());\n });\n });\n});\n\n\nYou can then style the .popup class to position it correctly and add any additional styling you want.
原文地址: https://www.cveoy.top/t/topic/qfhM 著作权归作者所有。请勿转载和采集!