Hold cursor change?

So I want to change the cursor from

#sideBar ul li .template{
 cursor:pointer;
}

perhaps the cursor: move; when the user drags ... is there something that I can use in jQuery or html to make this happen, you hold down the mouse button

+3
source share
5 answers

Instead of changing css in your javascript code, save it by simply changing one class that will update your element as many times as you want. I added the: hover pseudo-class because I'm not sure what cursorworks without it.

In addition, live works for any element added in the future, but the binding does not.

Css:

#sideBar ul li .template{
 cursor:pointer;
}

#sideBar ul li .template.mouseDown:hover{
 cursor:auto; /* or whatever cursor */
}

JavaScript:

$("#sideBar ul li .template").live("mousedown", function () {
    $(this).addClass("mouseDown");
}).live("mouseup", function () {
    $(this).removeClass("mouseDown");
});
+11
source

css- mousedown jQuery. mouseup(), , .

:.

$(document).ready(function() {
    $('#sideBar ul li .template').mousedown(function() {
        $(this).css('cursor', 'move');
    });
    $('#sideBar ul li .template').mouseup(function() {
        $(this).css('cursor', 'pointer');
    });
});
+2

, , , , mousedown.

mousedown , , mousemove. ( , mousemoves, )

mousemove CSS , . , .

, drop (mouseup) mousedown.

OS Desktop , , - , - , .

+2

- :

someFunc({
  onstart: function(){
     $(document.body).css( 'cursor', 'move' );
  },

  onstop: function(){
     $(document.body).css( 'cursor', 'auto' );
  }
});

onstart onstop, .


, mousedown mouseup:

$(el)
  .mousedown(function(){
    $(this).css( 'cursor', 'move' );
  })
  .mouseup(function(){
    $(this).css( 'cursor', 'auto' );
  });
+1

Of course you can do it. JQuery function . MouseDown can be set as a handler, then you only need to change css. Heres a example

$('.someElement').mousedown(function()
{
   $(this).css('cursor', 'move');
});
$('.someElement').mouseup(function()
{ 
   $(this).css('cursor', 'pointer');
});
+1
source

Source: https://habr.com/ru/post/1772737/


All Articles