<!-- Include jQuery from CDN --> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> |
$(selector).animate({ properties }, duration, easing, complete); |
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>jQuery Animation</title> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <style> #animatedElement { position: relative; width: 100px; height: 100px; background-color: blue; } </style> </head> <body> <div id="animatedElement"></div> <script> $(document).ready(function() { // Animation $("#animatedElement").animate({ opacity: 0.5, left: '+=150' // relative left position }, 1000, 'swing', function() { // Animation complete console.log('Animation complete!'); }); }); </script> </body> </html> |
These methods can be combined and customized to create more complex animations. Always refer to the jQuery documentation for detailed information and examples.