Answer the question
In order to leave comments, you need to log in
How to properly wrap jqueryUI slider initialization?
There is this slider:
// Значения
var sliderVariables = {
minValue: parseInt( $( ".price-slider__min" ).data( "range-slider-min" ) , 10 ),
maxValue: parseInt( $( ".price-slider__max" ).data( "range-slider-max" ) , 10 )
}
// Инициализация слайдера
$( ".price-slider" ).slider({
range: true,
min: sliderVariables.minValue,
max: sliderVariables.maxValue,
values: [ sliderVariables.minValue, sliderVariables.maxValue ],
slide: function( event, ui ) {
$( ".price-slider__min" ).attr( "value", ui.values[0] );
$( ".price-slider__max" ).attr( "value", ui.values[1] );
}
});
// Инициализация начальных значений
$( ".price-slider__min" ).attr( "value", $( ".price-slider" ).slider( "values", 0 ) );
$( ".price-slider__max" ).attr( "value", $( ".price-slider" ).slider( "values", 1 ) );
// Изменение положения ползунков в зависимости от значения поля (мин)
$( document ).on( "change", ".price-slider__min", function() {
changePriceSliderFieldMin( $( this ) );
});
function changePriceSliderFieldMin( field ) {
if (
( field.attr( "value" ) > sliderVariables.maxValue )
|| ( field.attr( "value" ) > $( ".price-slider" ).slider( "values", 1 ) )
) {
field.attr( "value", $( ".price-slider" ).slider( "values", 1 ) );
$( ".price-slider" ).slider( "values", 0, $( ".price-slider" ).slider( "values", 1 ) );
} else if ( field.attr( "value" ) < sliderVariables.minValue ) {
$( ".price-slider" ).slider( "values", 0, sliderVariables.minValue );
} else {
$( ".price-slider" ).slider( "values", 0, field.attr( "value" ) );
}
}
// Изменение положения ползунков в зависимости от значения поля (макс)
$( document ).on( "change", ".price-slider__max", function() {
changePriceSliderFieldMax( $( this ) );
});
function changePriceSliderFieldMax( field ) {
if (
( field.attr( "value" ) < sliderVariables.minValue )
|| ( field.attr( "value" ) < $( ".price-slider" ).slider( "values", 0 ) )
) {
field.attr( "value", $( ".price-slider" ).slider( "values", 0 ) );
$( ".price-slider" ).slider( "values", 1, $( ".price-slider" ).slider( "values", 0 ) );
} else if ( field.attr( "value" ) > sliderVariables.maxValue ) {
field.attr( "value", sliderVariables.maxValue );
$( ".price-slider" ).slider( "values", 1, sliderVariables.maxValue );
} else {
$( ".price-slider" ).slider( "values", 1, field.attr( "value" ) );
}
}
Answer the question
In order to leave comments, you need to log in
First
, jQuery = $.noConflict(); // remove the jQ global, do it immediately after the request to the jquery.min.js file
Some of the ancient grandfathers of our profession loved to poke their main library into a dollar. It doesn't matter if it's jquery or not. It happens that two libraries one replaces the other and then both do not work.
then like this:
(function ($, App) {
// ваш код
$(function () {
// ваш код после DOM-ready
});
})(jQuery, App = window.App || {});
<script src="">
to catch the event when the script is connected to the site, but even before the ondomready is finishedDidn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question