While I am on the JQuery subject, with the previous article for the table game, I have decided to enrich it a little. 🙂
Thus, adding some nice animation functions for JQuery – fadeIn(); slideToggle(); slideUp, animate() and their back functions.
What is interesting about these functions? They work pretty well and only the animate() function probably deserves a little more attention, because we may use it in a chain – e.g. in the example I am animating the increasing and the decreasing of the jellyfish as two functions, triggered with the button “Animate”.
Pretty much that is all. Here comes the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
<html> <head> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $(document).ready(function(){ $("img").click(function(event){ $("#information").html("You clicked over an image <hr>"); }); $("img").mousemove(function(event){ var coordinates = ""+ event.pageX + "< -- >" + event.pageY + ""; $("#information").html("You are moving over an image <hr>" + coordinates); }); $("img").mouseout(function(event){ $("#information").html("Test"); }); $("#information").mousemove(function(event){ $(this).html("<i>Can you find how to start Youtube?</i>"); }) $("#btn1").click(function(){ $("img").slideUp("slow"); }); $("#btn2").click(function(){ $("img").slideDown("fast"); }); $("#btn3").click(function(){ $("#i2").slideToggle(1000); $("#i3").slideToggle(100000); }); $("#btn4").click(function(){ $("#information").fadeIn(); }); $("#btn5").click(function(){ $("#information").fadeOut(); }); $("#btnA").click(function(){ $("#i2").animate({ width: "100%",opacity: 0.5},{duration:2000}) .animate({ width:"40%",opacity:0.9},{duration:2000}); }); }); </script> </head> <body> <h1>VitoshAcademy.Com Table Game</h1> <table border = "1" align="center"> <tr> <td><button id="btn1">Slide Down</button></td> <td><img src="images/i2.jpg" id="i2" height="40%"/></td> </tr> <tr> <td><img src="images/i3.jpg" id="i3" height="40%"/></td> <td id="information" bgcolor="lightblue"></td> </tr> <tr> <td><button id="btn2">Slide Up</button></td> <td><button id="btn3">Toggle</button></td> </tr> <tr> <td><button id="btn4">Fade in</button></td> <td><button id="btn5">Fade Out</button></td> </tr> <tr> <td><button id="btnA">Animate</button></td><td>Advertise here!</td> </tr> </table> </body> </html> |
Enjoy it also in GitHub. 🙂