jQuery UI Slider with Price Range: Implementation and Customization
This code sets up a jQuery UI slider with a price range from 0 to 10,000,000. The slider is initialized with the starting values of 0 and 10,000,000. Here's a breakdown of the code and its functionality:
var min = 0;
var max = 10000000;
$(function() {
$( '#slider-range' ).slider({
range: true,
min: min,
max: max,
step: 50000,
values: [ 0, 10000000 ],
slide: function( event, ui ) {
$( '#amount' ).html( '$' + ui.values[ 0 ] + ' - $' + ui.values[ 1 ] );
$( '#min' ).val(ui.values[ 0 ]);
$( '#max' ).val(ui.values[ 1 ]);
$(ui.handle).attr('data-value', ui.value); // Update handle popup value
$('#qp_has_price').attr('data_value', ui.values[ 0 ]+'to'+ui.values[ 1 ]);
$('.qq_price_range .qq_selected_terms').html( ui.values[ 0 ]+','+ui.values[ 1 ]);
$('.qq_clear_all_filters').prop('disabled', false);
setQueryStringParameter('price', ui.values[ 0 ]+'to'+ui.values[ 1 ]);
qq_call_loads();
}
});
$( '#amount' ).html( '$' + $( '#slider-range' ).slider( 'values', 0 ) +
' - $' + $( '#slider-range' ).slider( 'values', 1 ) );
// Initialize handle popups with default values
// Initialize handle popups with default values
$('#slider-range .ui-slider-handle:first').attr('data-value', min);
$('#slider-range .ui-slider-handle:last').attr('data-value', max);
});
Explanation:
var min = 0; var max = 10000000;: These variables define the minimum and maximum values for the slider.$(function() { ... });: This is a jQuery function that ensures the code executes after the DOM is fully loaded.$( '#slider-range' ).slider({ ... });: This line creates the slider element with IDslider-rangeand sets its properties:range: true: Enables a range slider, allowing the user to select a range.min: min: Sets the minimum value to0.max: max: Sets the maximum value to10,000,000.step: 50000: Specifies the interval between slider increments.values: [ 0, 10000000 ]: Sets the initial starting values for the slider handles.slide: function( event, ui ) { ... }: Defines a function that executes whenever the slider handle is moved. This function updates the price display, updates input fields (presumably for storing the values), and interacts with other elements on the page (based on thedata_valueandqq_class interactions). The starting value for the slider is 0.
$( '#amount' ).html( ... );: This line initializes the display of the price range on the page.$('#slider-range .ui-slider-handle:first').attr('data-value', min);and$('#slider-range .ui-slider-handle:last').attr('data-value', max);: These lines set the initial values for the slider handle popups.
The code also includes functionality to update the slider's appearance and behavior based on user interaction. You can adapt the slide function to implement custom features based on your specific requirements.
原文地址: https://www.cveoy.top/t/topic/qf8L 著作权归作者所有。请勿转载和采集!