I am trying to change the padding on an image by using a slider input. The idea is that users can upload an image an customise it. One of the option is a slider to change horizontal padding (one slider for each). Each slider have a values from -50 to 50 with a default value of 0. For example, if a user moves the 'horizontal padding slider' to the left (negative values), both left and right padding will decrease, and if the move the slider right (positive values) it will increase both left and right padding.
I have created the HTML slider with the values. Then, within the javascript file, I have created an event listener for the input value and a function to change it but is not working at all.
HTML CODE:
<form class="range-field mt-2">
<input type="range" min="-50" max="50" value="0" id="horizontal-padding"
step="2" />
</form>
JAVASCRIPT CODE:
var slider = document.getElementById("horizontal-padding").value;
var mycanvas = document.getElementById("mycanvas");
slider.addEventListener('change', function() {
mycanvas.style.padding = slider.value;
});
Anyone can please let me know whats wrong? many thanks in advance!