Using jQuery animates the first div's left property and synchronizes the remaining divs

  • جي كويري

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 );
    }
  });
});
هل كان المحتوى مفيد؟

معلومات ذات صلة

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...