Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing a function with a parameter to hover in jQuery
    primarykey
    data
    text
    <p>I am new to jQuery and I feel like I missing something very obvious and fundamental but I can't quite wrap my head around it.</p> <p>In any case I had a bit of code that would animate the stroke width to a wider amount when the object was hovered over and it worked:</p> <pre><code>$(function() { $("#wheel1").hover(grow1, shrink1); }); function grow1(evt) { $("#wheel1").animate({'stroke-width':'100'},300); $("#circle1container").css({'display':'block'}); $("#circle1container").animate({'opacity':'1'},300); } function shrink1(evt) { $("#wheel1").animate({'stroke-width':'55'},300); $("#circle1container").animate({'opacity':'0'},300); } </code></pre> <p>But I had 10 other objects that I also wanted to do this for, so rather than copying and pasting this 9 more times and changing the number 9 times, I tried to consolidate it and this did not work:</p> <pre><code>$(function() { $("#wheel1").hover(grow("1"), shrink("1")); $("#wheel2").hover(grow("2"), shrink("2")); $("#wheel3").hover(grow("3"), shrink("3")); $("#wheel4").hover(grow("4"), shrink("4")); $("#wheel5").hover(grow("5"), shrink("5")); $("#wheel6").hover(grow("6"), shrink("6")); $("#wheel7").hover(grow("7"), shrink("7")); $("#wheel8").hover(grow("8"), shrink("8")); $("#wheel9").hover(grow("9"), shrink("9")); $("#wheel10").hover(grow("10"), shrink("10")); function grow(number) { var name = "#wheel" + number; $("#wheel" + number).animate({'stroke-width':'100'},300); $("#circle" + number + "container").css({'display':'block'}); $("#circle" + number + "container").animate({'opacity':'1'},300); } function shrink(number) { $("#wheel" + number).animate({'stroke-width':'55'},300); $("#circle" + number + "container").animate({'opacity':'0'},300); } }); </code></pre> <p>Probably still not the most efficient way, but a bit less lengthy and easier to change I thought. I'm just not sure what the deal is here. Any help welcome, thank you!</p> <p><a href="http://jsfiddle.net/F4Yjj/5/" rel="nofollow">http://jsfiddle.net/F4Yjj/5/</a> This shows the object I am trying to animate on hover with the hover working for the green shape (the first bit of code in this message).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload