Try It Editor
Tip: Press
Ctrl/⌘ + Enter
to Run
▶ Run
Reset
Copy
Download
Code
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>animate() basics</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> <style>#box{position:relative;width:60px;height:60px;background:#ffcc80;margin-top:8px}</style> </head> <body> <button id="move">Move + Opacity</button> <div id="box"></div> <script> $("#move").on("click", function(){ $("#box").animate({ left: "+=120", opacity: 0.3 }, 400) .animate({ top: "+=60", opacity: 1 }, 300); }); </script> </body> </html>
Output