Javascript 如何使用jQuery将光标从指针更改为手指?
这可能真的很容易,但我以前从未做过。如何将光标改为手指(如单击链接)而不是常规指针 以及如何使用jQuery实现这一点,因为这就是我使用它的目的Javascript 如何使用jQuery将光标从指针更改为手指?,javascript,jquery,css,Javascript,Jquery,Css,这可能真的很容易,但我以前从未做过。如何将光标改为手指(如单击链接)而不是常规指针 以及如何使用jQuery实现这一点,因为这就是我使用它的目的 $('selector').css('cursor', 'pointer'); // 'default' to revert 我知道这可能会让你的原始问题感到困惑,但“手指”光标实际上被称为“指针” 正常箭头光标仅为“默认” 更新!新的和改进的!查找插件@ 另一方面,虽然很简单,但我已经创建了一个jQuery插件(),它使得在任何元素上更改光标都
$('selector').css('cursor', 'pointer'); // 'default' to revert
我知道这可能会让你的原始问题感到困惑,但“手指”光标实际上被称为“指针”
正常箭头光标仅为“默认”
更新!新的和改进的!查找插件@
另一方面,虽然很简单,但我已经创建了一个jQuery插件(),它使得在任何元素上更改光标都像
$(“元素”).cursor(“指针”)
一样简单
但这还不是全部!立即行动,您将免费获得手动功能位置
&ishover
!没错,两个非常方便的光标函数。。。免费
它们的工作原理与演示中看到的一样简单:
$("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");
此外:
供应有限,现在行动吧
如何将光标改为手指(如单击链接)而不是常规指针
使用CSS属性cursor
,不需要jQuery
,实现这一点非常简单
您可以在中阅读更多关于:和
.default{
游标:默认值;
}
.指针{
光标:指针;
}
这很直截了当 HTML
<input type="text" placeholder="some text" />
<input type="button" value="button" class="button"/>
<button class="button">Another button</button>
如果可能的话,通过CSS(比如使用:hover选择器)执行此操作,并完全避免使用jquery。@Who-确定,但是如果更改光标是依赖于JS的功能的一部分(比如说您有一个滑块),那么如果用户关闭了JS,您就不会希望光标更改。我将此与
$('selector').CSS结合使用('cursor','auto');
将鼠标移出指针区域时去除样式。CSS类可能会更干净…使用$('…')。addClass('someclass')
和$('…')。将其应用于body标记并更改为自定义光标时,removeClass('someclass')
。CSS('cursor',url(openhand.cur)4,move;');它似乎不起作用。我不知道这是否是jquery或chrome中的错误。不过,我还没有在其他浏览器上测试过。
<input type="text" placeholder="some text" />
<input type="button" value="button" class="button"/>
<button class="button">Another button</button>
$(document).ready(function(){
$('.button').css( 'cursor', 'pointer' );
// for old IE browsers
$('.button').css( 'cursor', 'hand' );
});