gpt4 book ai didi

javascript - 光标:鼠标抓取javascript

转载 作者:行者123 更新时间:2023-11-30 06:54:28 25 4
gpt4 key购买 nike

我有两张图片:一张是张开的手,一张是抓着的手。我希望一个简单的“onmousedown”和“onmouseup”函数有助于制作出著名的抓手,您可以在类似谷歌地图的东西中看到它。但...抱歉,从头开始:我有一个简单的 DIV,除了他的背景之外什么都没有。当我按住鼠标并开始“拖动”光标时,应该启动一个功能并将光标从“手打开”更改为“手抓”。但是光标变成了文本的选择器,而不是我想要的。有什么帮助吗?这是例子

<div onmousedown="function(){this.style.cursor='url(handgrab.png)'}"
onmouseup="function(){this.style.cursor='url(handopen.png)'}"
</div>

我唯一想要的是在将鼠标拖动到 DIV 中时更改光标。抱歉这个内联选择,但我不想写所有的 JS 文件...

最佳答案

您应该通过类名访问它。它让生活更轻松。

试试这个方法:-

HTML:

<div onmouseup="this.className='openHand'" onmousedown="this.className='closeHand'">
Mouse Down and Up Events
</div>​​​​​​​​​​​​​​​​​​​​​​​​​​

CSS:

.​openHand​ {
cursor: url(https://mail.google.com/mail/images/2/openhand.cur), default !important;
}

.closeHand {
cursor: url(https://mail.google.com/mail/images/2/closedhand.cur), default !important;
}​

引用 LIVE DEMO

关于javascript - 光标:鼠标抓取javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13103735/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com