N
N
Nitrino2013-01-27 21:56:56
JavaScript
Nitrino, 2013-01-27 21:56:56

jquery to jquery coffeescript hover handling?

I do a background change when the cursor is not on the element, in pure jquery it looks like this:

$("li").hover(<br>
  // При наведении курсора<br>
  function () {<br>
    $("i",this).css("background-image", "url(assets/blue-icon.png)");<br>
  },<br>
  // При убирании курсора<br>
  function () {<br>
    $("i",this).css("background-image", "url(assets/white-icon.png)");<br>
  }<br>
);<br>

using coffeescript, I process hover like this:
$("li").hover -><br>
  $("i",this).css("background-image", "url(assets/blue-icon.png)")<br>

how to handle the second part of the action when the cursor is removed?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Miniwe, 2013-01-27
@Nitrino

$("li").hover (
-> $("i", @).css "background-image", "url(assets/blue-icon.png)"
-> $("i", @). css "background-image", "url(assets/white-icon.png)"
)
and js2coffee.org/

D
Defff, 2013-01-28
@Defff

In jQuery it's better like this:

$(document).ready(function(){
 $("li").mouseenter(function(){
      $( i,this).css({"background-image": "url(assets/blue-icon.png)"});
    }).mouseleave(function(){
      $( i,this).css({"background-image": "url(assets/white-icon.png)"});
    });
});

Hover - shakes when hovering on the edges

N
Nitrino, 2013-01-28
@Nitrino

.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question