Using jQuery animates the first div's left property and synchronizes the remaining divs.
Note: Use the step function to set their left properties at each stage of the animation.
<!DOCTYPE html> <html> <head> <script src="https://code.jquery.com/jquery-git.js"></script> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>Animates the first div's left property and synchronizes the remaining divs.</title> </head> <body> <p><button id="run">Click to Run »</button></p> <div class="block"></div> <div class="block"></div> <div class="block"></div> <div class="block"></div> </body> </html>
CSS Code:
div { position: relative; background-color: #B0E0E6; width: 45px; height: 45px; float: left; margin: 5px; }
JavaScript Code :
$( "#run" ).click(function() { $( ".block:first" ).animate({ left: 100 }, { duration: 2000, step: function( now, fx ){ $( ".block:gt(0)" ).css( "left", now ); } }); });
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
CSS Code:
JavaScript Code :