Wednesday 15 January 2014

mouseenter - How to create a jquery mouseover for multiple divs by id? -


Hi, I am trying to create a series of mouseover events together, but I'm really new to JavaScript and I'm really confused. I have 5 buttons like a child and I want to make a function to include them all. I do not use the divs class for any other function that is not included here. I believe I have to use the ID for Mouseover $ ('# Trigger 1'). Mouseover (function () {$ ('# roll1r'). Fade ('slow');});

I use conditional to define which element I want to hide, but I'm not sure how to define a variable And they have to spend in the Fade Out function. I have tried all kinds of syntax to pass it as string, but I do not know what the problem is

  $ ('# trigger1, #trigger2, #trigger 3 '). Mouseover (function () {var roll = null; var joe = $ (this) (=== "# trigger2") {roll = "$ ('# roll2r')";} and if (that is == = "#trigger3") {roll = "$ ('# roll3r')";} console.log (roll); roll.fadeaut ({duration: 300, // failed: that.hide ()})} }); & Lt; Div class = "button container" & gt; & Lt; Div id = "buttonbg1" & gt; & Lt; Img id = "roll1" class = "translatebuttons" src = "image / buttonover page" alt = "translation games" & gt; & Lt; Img id = "roll1r" class = "translatebuttons" src = "image / button .png" alt = "translation games" & gt; & Lt; Div class = "translatebuttons" id = "tr1" & gt; & Lt; / Div & gt; & Lt; Div id = "trigger1" class = "translatebuttons" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "buttonbg2" & gt; & Lt; Img id = "roll2" class = "translatebuttons" src = "image / buttonover page" alt = "translation games" & gt; & Lt; Img id = "roll2r" class = "translatebuttons" src = "image / button .png" alt = "translation games" & gt; & Lt; Div class = "translatebuttons" id = "tr2" & gt; & Lt; / Div & gt; & Lt; Div id = "trigger2" class = "translatebuttons" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "buttonbg3" & gt; & Lt; Img id = "roll3" class = "translatebuttons" src = "image / buttonover page" alt = "translation games" & gt; & Lt; Img id = "roll3r" src = "picture / button png" alt = "translation games" & gt; & Lt; Div class = "translatebuttons" id = "tr3" & gt; & Lt; / Div & gt; & Lt; Div id = "trigger3" class = "translatebuttons" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;    

are you looking for something like that? In a way, you can simplify the code with only one handler:

  $ ('[^ ^ ^ ^]). Hover (function {var roll = $ (this.id.replace (/ trigger /, '# roll') + 'R'); Roll.FedToggle ({duration: 300});});   

  • Use the selector to select all triggers
  • Use
  • Use to toggle the rolling state of the roll.
  • Shortcut for the mouse
  • Use simple ridge ripple to calculate the relevant roll ID.

No comments:

Post a Comment