Skip to content

Instantly share code, notes, and snippets.

@codecobber
Created November 9, 2016 10:10
Show Gist options
  • Save codecobber/2c9cd1a9bc89b03eccfe2fe8f5cd0780 to your computer and use it in GitHub Desktop.
Save codecobber/2c9cd1a9bc89b03eccfe2fe8f5cd0780 to your computer and use it in GitHub Desktop.
jQuery slider changes block height
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Slider - Range with fixed maximum</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#slider-range-max" ).slider({
range: "max",
min: 100,
max: 600,
value: 150,
slide: function( event, ui ) {
$( "#amount" ).val( ui.value );
$("#box").css("height", $( "#slider-range-max" ).slider( "value" ));
}
});
$( "#amount" ).val( $( "#slider-range-max" ).slider( "value" ) );
} );
</script>
<script>
$(document).ready(function(){
$("#btn1").click(function(){
$("#box").animate({height: "300px"});
});
$("#btn2").click(function(){
$("#box").animate({height: "100px"});
});
});
</script>
</head>
<body>
<button id="btn1">Animate height</button>
<button id="btn2">Reset height</button>
<div id="box" style="background:#98bf21;height:100px;width:100px;margin:6px;"></div>
<p>
<label for="amount">Size:</label>
<input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
</p>
<div id="slider-range-max"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment