0

I want to find real time if the range slider is moved left or right using jquery. Thanks following is my current implementation.

$("#zoom-slider").on("input", function(e) {
var curr_val = $("#zoom-slider").val();
if( curr_val > zoom_slider )
{
   console.log( " +ive : right" );
}else
{
   console.log( " -ive : left" );
}
zoom_slider = curr_val;
});

But i was asking if there is any event.

1
  • After your edit, your current implementation is fine. Commented Aug 6, 2015 at 8:18

1 Answer 1

6

Using the input event alongside storing the previous value for comparison should do what you need:

var oldVal;
$("input").on("input", function() {
    var newVal = $(this).val();
    if(newVal > oldVal) {
        $("div").text("right");
    }
    else if(newVal < oldVal) {
        $("div").text("left");
    }
    oldVal = newVal;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="range">
<div></div>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.