Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

JavaScript animations

<!DOCTYPE html>
<html>
<style>
#container {
  width: 400px;
  height: 400px;
  border-radius: 10%;
  position: relative;
  background: rgb(130, 240, 231);
}
#animate {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 3px solid rgb(218, 15, 15);
  position: absolute;
  background-color: rgb(51, 255, 0);
}
</style>
<body>

<p><button onclick="myMove()">Click Me</button></p> 

<div id ="container">
  <div id ="animate"><br><p>(★‿★)</p></div>
  <br><br>
  <br><p>hello from mohammad alshraideh</p>
</div>

<script>
function myMove() {
  let id = null;
  const elem = document.getElementById("animate");   
  let pos = 0;
  clearInterval(id);
  id = setInterval(frame, 5);
  function frame() {
    if (pos == 350) {
      clearInterval(id);
    } else {
      pos++; 
      elem.style.top = pos + "px"; 
      elem.style.left = pos + "px"; 
    }
  }
}
</script>

</body>
</html>
Comment

js animations

<!DOCTYPE html>
<html>
<style>
#myContainer {
  width: 400px;
  height: 400px;
  position: relative;
  background: yellow;
}
#myAnimation {
  width: 50px;
  height: 50px;
  position: absolute;
  background-color: red;
}
</style>
<body>

<p>
<button onclick="myMove()">Click Me</button> 
</p>

<div id ="myContainer">
<div id ="myAnimation"></div>
</div>

<script>
var id = null;
function myMove() {
  var elem = document.getElementById("myAnimation");   
  var pos = 0;
  clearInterval(id);
  id = setInterval(frame, 10);
  function frame() {
    if (pos == 350) {
      clearInterval(id);
    } else {
      pos++; 
      elem.style.top = pos + 'px'; 
      elem.style.left = pos + 'px'; 
    }
  }
}
</script>

</body>
</html>
Comment

animation js

• pause() - Tạm thời đóng băng trạng thái hiện tại của animation
• play() - Tiếp tục thực hiện animation hoặc chạy lại animation trong trường hợp animation đã hoàn thành
• reverse() - thực hiện animation với chiều ngược lại
• finish() - Đi đến cuối của animation (đi đến đầu trong trường hợp sử dụng reverse)
• cancel() - Dừng animation và trở lại trạng thái đầu tiên trước khi thực hiện animation
Comment

PREVIOUS NEXT
Code Example
Javascript :: link external file by url using javascript 
Javascript :: bundle 
Javascript :: currency conversion to locale string js 
Javascript :: node js login and registration 
Javascript :: react insert variable into string 
Javascript :: check if field exists in object javascript 
Javascript :: object literals and array literals in javascript 
Javascript :: jquery class 
Javascript :: shell 
Javascript :: Origin http://localhost:3002 is not allowed by Access-Control-Allow-Origin. 
Javascript :: class in javascript 
Javascript :: js setinterval run immediately 
Javascript :: how to decode jwt token at frontend 
Javascript :: dynamic input fields with radio button 
Javascript :: if( request()-ajax()==false 
Javascript :: function javascript 
Javascript :: How to get random no. without math.random() function 
Javascript :: 2 dimensional array index of element value 
Javascript :: jquery get search parameter 
Javascript :: how to lose overflow in js without hidden 
Javascript :: How to add multiple classes to a ReactJS Component 
Javascript :: react native firebase login with facebook 
Javascript :: react route path 
Javascript :: react native bottom sheet above the bottom menu 
Javascript :: Discord.js v13 / command handler 
Javascript :: how to delete an exact element of array 
Javascript :: how to use location.pathname 
Javascript :: javascript make http request 
Javascript :: switch expression bools 
Javascript :: react datepicker documentation 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =