- xml - AJAX/Jquery XML 解析
- 具有多重继承的 XML 模式
- .net - 枚举序列化 Json 与 XML
- XML 简单类型、简单内容、复杂类型、复杂内容
我正在构建一个 Web 应用程序,它涉及从网页内和其他应用程序(例如 word 和 pdf 文档)拖放大量文本。如果按下(单击)或向上(释放),我需要获取鼠标的当前状态。目前,如果我在网页中拖动文本,我可以获取鼠标的当前状态,但如果鼠标来自另一个应用程序说出的单词并拖动一些文本,则无法获取鼠标状态。非常感谢任何获取鼠标按下或向上状态的指针。
最佳答案
我理解的问题是,如果在窗口外按下鼠标左键(用于拖动操作),您需要确定是否按下鼠标左键。
有很多问题:
我想出了这个解决方案:
/**
* keeps track of the current active mouse button.
* @param notifier {Function} called when the active button is updated.
* @param oneCallPerStateChange {Boolean} (defaults to false) if true the notifier will be called only when the active button changes.
*/
function initActiveButtonWatcher(notifier, oneCallPerStateChange) {
// create variable to store button states.
var _activeButton = -1, activeButton = 0
// function to set the current active button.
function updateMouseState(e) {
// update active button.
activeButton = typeof e.buttons === "number" ? e.buttons : e.which
// notify if the active button is different.
if ( oneCallPerStateChange? (_activeButton !== activeButton && typeof notifier === "function") : (typeof notifier === "function")) {
notifier(activeButton)
}
// store the last state in order to be able to tell if the state has changed.
_activeButton = activeButton
}
// function to get the current active button.
function getButtonState() { return activeButton }
// update the button state when the mouse is moved
// or an item is dragged into the window.
window.addEventListener("mousemove", updateMouseState, false)
window.addEventListener("dragover", function() { updateMouseState({which: 1}) }, false)
window.addEventListener("dragleave", function() { updateMouseState({which: 0}) }, false)
// expose the getter on the global object.
window.getButtonState = getButtonState
}
上述解决方案绑定(bind)到 mousemove 事件和 dragover 事件。Chrome 在 dragover 事件中获得了一个具有正确按钮值的有效事件对象,但我发现 FireFox 没有。我觉得鼠标左键的状态在拖拽操作中很明显,应该是按下,对吧?不单击和移动就不能拖动。所以我只是在 dragover 上将状态设置为 1(左下)。同样,在 dragleave 上,该值设置为零。
您将执行所有正常的 dragover、dragstart、end、drop 等处理以防止默认浏览器操作,并且 window.getButtonState() 返回的值应始终是当前事件鼠标按钮的值。
下面是一些将页面中第一个 h1 标签的值设置为当前按下的按钮的用法示例:
;(function() {
var active = document.getElementsByTagName("h1")[0]
function translate(n) {
switch (n) {
case 0:
return "none"
break;
case 1:
return "left"
break;
case 2: case 4: // Firefox calls it 4, the values differ between browsers I find.
return "middle"
break;
case 3:
return "right"
}
}
initActiveButtonWatcher(
function(currentActive) {
active.innerHTML = "Active button: " + translate(currentActive)
}
)
})()
您必须对跨浏览器进行一些调整以处理不同的值(FF 报告中间按钮为 4,等等)但您应该能够使用此方法相当好地获得当前按钮。
关于javascript - 在 javascript 或 jquery 中检测鼠标的当前状态,即向下或向上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10103298/
我正在使用面部跟踪进行 HCI(人机交互)。我正在尝试使用面部控制 PC。 我有 3x3 二维网格按钮。1 2 34 5 67 8 9 假设,当前焦点在按钮 5 上。如果我按向上箭头,则焦点将在 2
我正在为蛇和梯子制作一 block 板,到目前为止,我已经按降序打印了板。但是,我需要以正确的方式打印电路板。 编辑“螺旋下降”意味着 100...91 81...90 80...71 ...
我有一个可以响应式调整大小的菜单,因此每次调整大小时 div (#menuWFhover) 的内容都会重新排列,因此 div 根据窗口大小具有不同的高度。 当我使用 jQuery slideDown/
我们从服务器获取数据并附加 ListView 。我们的问题是,当向上/向下滚动时,它首先显示白屏,然后显示数据。向下/向上滚动时,之前出现的白屏应删除 for (var i=0; i");
我想要一个汉堡图标动态改变颜色的代码,以适应网站的黑色部分/部分和白色。它最初是 3 段白色,js 代码几乎是好的和正确的,但是当它在白色部分时它一直闪烁,并在红色和白色之间闪烁。 js var to
我对点击事件的页脚位置有疑问。我正在使用 bootstrap css,我有一个可折叠元素(bootstrap 中的 Accordion ),当它折叠时它有一个名为 .accordion-toggle.
在此代码段中,使用关键帧和动画并显示无/ block ,div 动画以在悬停时向下滑动。 h1 { padding: 20px; } div { width: 100%; background
我需要对一个 float 进行四舍五入。例如 4.00011 。内置函数 round() 总是在数字 > .5 时向上舍入,在 = 0 val *= 10 ** precision r
我正在尝试就地缩小文件。 我正在用另一个文件的内容替换一个文件的内容,完成后我想确保源文件是否小于目标文件,目标文件是否正确收缩。 (为什么:因为dest文件是一个备份,写入media的开销很大,所以
似乎每当我用一个负整数除以一个正整数时,我都需要它向下舍入 (向 -inf),而不是向 0。但 C# 和 C++ 都向 0 舍入。 所以我想我需要一个 DivideDownward() 方法。我可以用
考虑这个简单的代码: document.addEventListener( 'keypress', function() { console.log( 'press' ); } ); document
有什么方法可以检查 Azure 资源(例如 Azure IoT 中心或事件中心)是否可用。我所说的可用是指它是否已关闭/工作/正常/启动?我是 Azure 的新手,如果有人能提供一些启发,那就太好了。
有什么方法可以检查 Azure 资源(例如 Azure IoT 中心或事件中心)是否可用。我所说的可用是指它是否已关闭/工作/正常/启动?我是 Azure 的新手,如果有人能提供一些启发,那就太好了。
我见过几个recyclerview的无限滚动示例,但它们都是向下滚动的。 我想要的是一次又一次地加载我的列表,但无论用户是从上面还是从下面滚动。 正常列表 向上滚动 向下滚动 这样可以通过无限滚动一遍
我正在使用带有 View 的 drupal 7,并且我正在使用我发现的向上/向下文本幻灯片的 jquery 脚本。它有效,但是当我尝试将它与带有 ajax 的 View 公开过滤器一起使用时,它似乎不
*场景 我希望制作一个类似于本网站上的 jquery 效果,它位于主 Flash 添加的右侧: http://www.commbank.com.au/ *问题 我已经开始了,但是用很多方法遇到了一些障
互联网。如果这与其他人没有什么关系,请原谅我,但我会将其留在这里,以防这是一个有效的问题。 我正在尝试创建一个文本区域字段,其中用户每次按下键(a-z),都会触发背景颜色更改(在数组中列出)。我一直在
我正在创建一个网络前端来控制一个小型机器人。 Ajax 调用将在 keydown 上进行,以启动机器人,并在 keyup 上进行停止。 我的问题是,当按下某个键时,keyup、keydown 和 ke
我在内容容器中有两个 div,一个向左浮动,另一个向右浮动。我正在使用屏幕的整个宽度。左 div 宽度为 1290px,右 div 宽度为 625px。有时,在加载页面时,滚动条会更改可用屏幕宽度的宽
请看这个UI sketch图片,我在某个站点的侧边栏(黑框)中有这个 div,当我向下滚动或向上滚动时,我不希望它隐藏...我希望它在我向下滚动和移动时自行向下移动当我向上滚动时向上滚动,这样它就永远
我是一名优秀的程序员,十分优秀!