i'm a Javascript beginner and now i have something too complex for me to solve. I will have to write this code block HUNDREDS of time, and the only difference will be in these 3 variables, which would change for every code duplicate.
fkbtn01, reak00, buttonf01.
Is there a way to solve this?...Thank you.
JS:
// START OF REPETITIVE CODING BLOCK
$(document).ready(function(){
var distanza = $('.fkbtn01');
$('.reak00').on('focus', function(){
var posizione = $(this).val();
distanza.css({left:posizione}).animate({
'left': (posizione *100 / 200)
});
});
$('.reak00').on('change', function(){
var posizione = $(this).val();
distanza.css({left:posizione}).animate({
'left': (posizione *100 / 200)
});
});
$('.reak00').on('focus', function(){
r = $('#reak00').val().toString(16);
var opacityRed = r / 100;
$("#buttonf01").css("background-color", "rgba(255,255,255," + opacityRed + ")");
$("#buttonf01").css("box-shadow", "0 0 25px rgba(255,127,50," + opacityRed + ")");
});
});
$('.reak00').on('change', function(){
r = $('#reak00').val().toString(16);
var opacityRed = r / 100;
$("#buttonf01").css("background-color", "rgba(255,255,255," + opacityRed + ")");
$("#buttonf01").css("box-shadow", "0 0 25px rgba(255,127,50," + opacityRed + ")");
});
// END OF REPETITIVE CODING BLOCK