How to change cursor from pointer to finger using jQuery?

前端 未结 4 1085
北恋
北恋 2020-12-12 16:36

This is probably really easy, but I\'ve never done it before. How do you change your cursor to the finger (like for clicking on links) instead of the regular pointer?

<
相关标签:
4条回答
  • 2020-12-12 17:18

    How do you change your cursor to the finger (like for clicking on links) instead of the regular pointer?

    This is very simple to achieve using the CSS property cursor, no jQuery needed.

    You can read more about in: CSS cursor property and cursor - CSS | MDN

    .default {
      cursor: default;
    }
    .pointer {
      cursor: pointer;
    }
    <a class="default" href="#">default</a>
    
    <a class="pointer" href="#">pointer</a>

    0 讨论(0)
  • 2020-12-12 17:27

    Update! New & improved! Find plugin @ GitHub!


    On another note, while that method is simple, I've created a jQuery plug (found at this jsFiddle, just copy and past code between comment lines) that makes changing the cursor on any element as simple as $("element").cursor("pointer").

    But that's not all! Act now and you'll get the hand functions position & ishover for no extra charge! That's right, 2 very handy cursor functions ... FREE!

    They work as simple as seen in the demo:

    $("h3").cursor("isHover"); // if hovering over an h3 element, will return true, 
        // else false
    // also handy as
    $("h2, h3").cursor("isHover"); // unless your h3 is inside an h2, this will be 
        // false as it checks to see if cursor is hovered over both elements, not just the last!
    //  And to make this deal even sweeter - use the following to get a jQuery object
    //       of ALL elements the cursor is currently hovered over on demand!
    $.cursor("isHover");
    

    Also:

    $.cursor("position"); // will return the current cursor position as { x: i, y: i }
        // at anytime you call it!
    

    Supplies are limited, so Act Now!

    0 讨论(0)
  • 2020-12-12 17:28
    $('selector').css('cursor', 'pointer'); // 'default' to revert
    

    I know that may be confusing per your original question, but the "finger" cursor is actually called "pointer".

    The normal arrow cursor is just "default".

    all possible default pointer looks DEMO

    0 讨论(0)
  • 2020-12-12 17:28

    It is very straight forward

    HTML

    <input type="text" placeholder="some text" />
    <input type="button" value="button" class="button"/>
    <button class="button">Another button</button>
    

    jQuery

    $(document).ready(function(){
      $('.button').css( 'cursor', 'pointer' );
    
      // for old IE browsers
      $('.button').css( 'cursor', 'hand' ); 
    });
    

    Check it out on JSfiddle

    0 讨论(0)
提交回复
热议问题