Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger custom cursor change on mousedown without mousemove event (jQuery)

Trying to change the cursor

I am trying to make a draggable scrollable image and as such am trying to change the cursor over an image when a variable is set to zoom mode so I can have good usability. What I am finding is that the cursor only changes once I have clicked the ".page" and THEN moved the mouse not just as I click the page as it should. Here is some example code:

$(".page").on("mousedown", function (evt) {
    if(model.zoomMode){
        $('.page').css('cursor','url("img/hand_closed.gif"),auto');
    }       
}).on("mouseup", function (evt) {
    if(model.zoomMode){
        $('.page').css('cursor','url("img/hand_open.gif"),auto');
    }
});

Another approach relying more on CSS

This seems to happen when I use classes to achieve the same effect as well. ie. zoom mode adds a class outside of the .page object and then the javascript is:

$(".page").on("mousedown", function (evt) {
    $('.page').addClass('mouseDown');
}).on("mouseup", function (evt) {
    $('.page').removeClass('mouseDown');
});

Then in the CSS:

.zoom .page:hover{
    cursor:url(../img/hand_open.gif),auto;
}

.zoom .page.mouseDown:hover{
    cursor:url(../img/hand_closed.gif),auto;
}

I am using chrome 18 to test. Anyone know a way to trigger the CSS cursor being applied without moving the mouse?

like image 371
Rudi Avatar asked Apr 06 '12 05:04

Rudi


People also ask

How do I trigger a Mousemove event?

The mousemove event occurs whenever the mouse pointer moves within the selected element. The mousemove() method triggers the mousemove event, or attaches a function to run when a mousemove event occurs. Note: Each time a user moves the mouse one pixel, a mousemove event occurs.

How do I change my cursor to a custom image in HTML?

Answer: Use the CSS cursor propertygif or . png (for Firefox, Chrome, Safari) and . cur for (for Internet Explorer). After that apply the cursor property with a comma-separated list of URLs pointing to these cursor images.

What is Mousemove?

The mousemove event is fired at an element when a pointing device (usually a mouse) is moved while the cursor's hotspot is inside it.


1 Answers

Short answer: No.

Long answer: Nope, sorry.

(source)

like image 144
Elliot Bonneville Avatar answered Oct 29 '22 14:10

Elliot Bonneville