• mouse over call function
    4 replies, posted
I want to call a JavaScript function on mouse over on a link. This is the link with the function in. [code] <a href="http://www.squidgytriangles.co.uk/index.php?page=home" onmouseover="movetri()">HOME</a> [/code]and here is the code that is in the head [code] <script src="http://code.jquery.com/jquery-1.4.4.js"> function movetri(){ alert("lol"); $("#triangles").animate({ left: "20", }, 500 ); } </script> [/code] The aim of this code of this code it to animate a small triangle in a div to move using jqeury on mouse over, am I doing this wrong? Is there a better way of doing this? OH one more thing to point out, this function isn't working even if I remove the jquery stuff, the alert isn't showing :/
Of course it doesn't work. It's suppose to be: [php] <script src="http://code.jquery.com/jquery-1.4.4.js"></script> <script type="text/javascript"> function movetri(){ alert("lol"); $("#triangles").animate({ left: "20", }, 500 ); } </script> [/php]
You should use jQuery's event hooks so you don't need any HTML.
OK, so the function calls now but the triangle isn't moving. [code] <script src="http://code.jquery.com/jquery-1.4.4.js"> </script> <script type="text/javascript"> function movetri(){ $("#triangles").animate({ left: "500", }, 500 ); } </script>[/code]
[code]<script type="text/javascript"> function movetri(){ $("#triangles").animate({ marginLeft: "500px", }, 500 ); } function() { $('#hover').hover(function() { movetri(); }); } </script> <a id="hover">Hover over me</a>[/code]
Sorry, you need to Log In to post a reply to this thread.