How is it possible to control CSS with a range slider via jQuery?
Some example code:
$('.font_size').on('input', function() { var fontsizeval = $(this).attr('value'); var fontsizemin = $(this).attr('min'); var fontsizemax = $(this).attr('max'); $('.text').css("font-size", fontsizeval + "px"); });
* { font-size: 12px; }.text { font-size: 120px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div class="text">Text <div> Font Size: <input class="font_size" type="range" value="120" min="30" max="200">
Would be very thankful for help!
use val()
instead of attr("value")
$('.font_size').on('input', function() { var fontsizeval = $(this).val(); var fontsizemin = $(this).attr('min'); var fontsizemax = $(this).attr('max'); $('.text').css("font-size", fontsizeval + "px"); });
* { font-size: 12px; }.text { font-size: 120px; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> Font Size: <input class="font_size" type="range" value="120" min="30" max="200"> <div class="text">Text <div>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.