Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change HTML range slider value with button?

I am using a HTML range slider to zoom in and zoom out an image. I also want to show two buttons with slider like + for zoom and − for zoom out. When a user clicks on either of these buttons, the slider should also be moved. But I am unable to do this. Here is my code.

<div id="slider">
    <input id="slide" type="range" min="330" max="1200" step="30" value="330" onchange="ImageViewer.sliderAction(this.value)" />
</div>

Here is my function:

var sliderAction = function (value) {
    $sliderChosen.html(value);
    $("#img").width(value);
    $("#img").height(value);
};

When I click the button, I tried this:

btnZoomIn.click(function() {
    $("#slide").value();  //Want to change value but value is undefined.
});

Is there any way to change slider value and move it as well on button click?

like image 661
umer Avatar asked Dec 16 '15 10:12

umer


People also ask

How do you set a range value in html?

The <input type="range"> defines a control for entering a number whose exact value is not important (like a slider control). Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the attributes below. Tip: Always add the <label> tag for best accessibility practices!

How do I customize my input range?

To style the range input with CSS you'll need to apply styles to two pseudo-elements: ::-webkit-slider-thumb and ::-webkit-slider-runnable-track . Find out how you can apply custom styling and make the range input more functional and appealing. Contents of the article: CSS selectors for the range input.


1 Answers

use val()

 btnZoomIn.click(function() {
               //if value < max
               $("#slide").val(parseInt($("#slide").val())+30);  
               $("#slide").trigger('change');
            });

https://jsfiddle.net/9jfst447/

like image 146
madalinivascu Avatar answered Oct 12 '22 07:10

madalinivascu