Javascript:如何在拖动过程中设置光标&在网站

Javascript: How can I set the cursor during a drag amp; drop operation on a website?(Javascript:如何在拖动过程中设置光标amp;在网站上放置操作?)
本文介绍了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 cursor 属性似乎只在您不按住鼠标按钮时才会启动.

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:如何在拖动过程中设置光标&amp;在网站上放置操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)