Javascript:在拖放过程中如何设置光标在网站上进行拖放操作? [英] Javascript: How can I set the cursor during a drag & drop operation on a website?

查看:67
本文介绍了Javascript:在拖放过程中如何设置光标在网站上进行拖放操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Chrome浏览器扩展程序,该扩展程序允许拖放在页面上的任何地方都放下某种操作.但是,当用户执行此操作时,通常会将光标更改为文本光标.

I am developing a Chrome browser extension that allows a drag & drop kind of operation everywhere on the page. However, while the user performs this operation the cursor is usually changed to the text cursor.

我该如何改变这种行为? CSS光标属性似乎仅在不按住鼠标按钮时才起作用.

How can I alter that behaviour? The CSS cursor property seems to only kick in when you're not holding the mouse button down.

PS:由于我正在开发Google Chrome浏览器的扩展程序,因此其他浏览器对我来说无关紧要.

PS: Since, I'm developing an extension for Google Chrome, other browser do not matter to me.

推荐答案

简单地覆盖"dragstart"消息处理程序以及"selectstart" ... 在功能中取消事件...

Simply override the "dragstart" message handler as well as the "selectstart"... While in the function cancel the event...

<script type="text/ecmascript>
window.addEventListener("dragstart", function(fEventObject){ CancelEvent(fEventObject); } );
window.addEventListener("selectstart", function(fEventObject){ CancelEvent(fEventObject); } );

function CancelEvent(fEventObject) 
{
   if (fEventObject.preventDefault) fEventObject.preventDefault();
   if (fEventObject.cancel != null) fEventObject.cancel = true;
}

</script>

这篇关于Javascript:在拖放过程中如何设置光标在网站上进行拖放操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆