0

I'm trying to do some thing like this: Hover on: '.painel li' if mousedown then: do the code I already do this:

$('.painel li').bind('mousedown hover', function () {
    // Code     
});

But, it doesn't work, anyone know how can I do that?

Thanks.

fsatyro
  • 3
  • 1
  • What doesn't work? What you want to do is not exactly clear. Do you want the same event for `mousedown` and `hover` or different ones? – Explosion Pills Jul 11 '12 at 16:58
  • I need when hover in element if mouse is down do the code, else don't do nothing, somthing like this: $('.painel li').bind('mousedown hover', function () { if(event.type == 'mousedown'){ //code } }); – fsatyro Jul 11 '12 at 17:09
  • Don't you have to hover over something to click it? – Explosion Pills Jul 11 '12 at 17:17

2 Answers2

0

You can try with .on():

$('.painel li').on('mousedown hover', function() {

});

Demo

Note

  • check here, .bind() is also working..
  • check that you include the jQuery library
  • wrap all jQuery code within $(document).ready(function() { // code }), in short $(function() { // code })

More

you can also separate event binding like following:

$('.painel li').mousedown(function() {
    console.log('mousedown');
}).hover(function() {
    console.log('hover');
});

Demo

Community
  • 1
  • 1
thecodeparadox
  • 86,271
  • 21
  • 138
  • 164
0

Try on instead:

$(".painel li").on("mousedown hover", function(event){
    alert('you made it');
});
Lowkase
  • 5,631
  • 2
  • 30
  • 48
  • Doesn't work, because if i Just Hover it, the message will apear, but i just want the message apear if while i'm hover the element the mouse is down – fsatyro Jul 11 '12 at 17:03
  • I see, not sure if you can combine those events like that. You would have to dig into jQuery to see if you can somehow trap both of those mouse events at the same time. The above selector is an OR condition, not an AND (i.e. - if mousedown OR hover events, then do something) – Lowkase Jul 11 '12 at 17:06
  • Take a look here, it should start you down the path of concatenating those events: http://stackoverflow.com/questions/2970973/mouseover-while-mousedown – Lowkase Jul 11 '12 at 17:07
  • That answer you linked to is nasty... a global variable!? Just use the `event.button` property. – Chris Baker Jul 11 '12 at 17:08
  • Actually... testing that. It doesn't look like the button property is being set for mouseover. Drag might be a better route, then. I'm doing some tests, will update my answer with results. No matter what, global variable should be avoided :p – Chris Baker Jul 11 '12 at 17:13
  • @Lokase this post help me, it's just what i was looking for, thanks – fsatyro Jul 11 '12 at 17:22