久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Firefox 在文本上拖動時觸發(fā) dragleave

Firefox firing dragleave when dragging over text(Firefox 在文本上拖動時觸發(fā) dragleave)
本文介紹了Firefox 在文本上拖動時觸發(fā) dragleave的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

限時送ChatGPT賬號..

我正在嘗試跟蹤整個屏幕的 dragenter/leave,到目前為止,這在 Chrome/Safari 中運行良好,由 https://stackoverflow.com/a/10310815/698289 如:

I'm attempting to track a dragenter/leave for the entire screen, which is so far working fine in Chrome/Safari, courtesy of the draghover plugin from https://stackoverflow.com/a/10310815/698289 as in:

$.fn.draghover = function(options) {
    return this.each(function() {

        var collection = $(),
            self = $(this);

        self.on('dragenter', function(e) {
            if (collection.size() === 0) {
                self.trigger('draghoverstart');
            }
            collection = collection.add(e.target);
        });

        self.on('dragleave drop', function(e) {
            // timeout is needed because Firefox 3.6 fires the dragleave event on
            // the previous element before firing dragenter on the next one
            setTimeout( function() {
                collection = collection.not(e.target);
                if (collection.size() === 0) {
                    self.trigger('draghoverend');
                }
            }, 1);
        });
    });
};

function setText(text) {
    $('p.target').text(text);
}

$(document).ready(function() {
    $(window).draghover().on({
        'draghoverstart': function() {
            setText('enter');
        },
        'draghoverend': function() {
            setText('leave');
        }
    });
});

但是,當我拖動文本項時,F(xiàn)irefox 仍然給我?guī)韱栴},這里有一個小提琴來演示:http://jsfiddle.net/tusRy/6/

However Firefox is still giving me problems when I drag over text items, here's a fiddle to demonstrate: http://jsfiddle.net/tusRy/6/

這是 Firefox 的錯誤還是可以用 JS 來馴服?還是有更穩(wěn)健的方法來執(zhí)行所有這些操作?

Is this a Firefox bug or can this be tamed with JS? Or is there a more robust method for performing all of this?

謝謝!

更新:將小提琴更新為 http://jsfiddle.net/tusRy/6/ 以減少混亂.解釋小提琴的預期行為:

UPDATE: Updated fiddle to http://jsfiddle.net/tusRy/6/ to reduce clutter a bit. To explain the expected behavior of the fiddle:

  • 將文件拖到窗口中,p.target 應該是黃色的ENTER".
  • 將文件拖出窗口,p.target 應該是紅色的LEAVE".
  • 在窗口中放置一個文件,p.target 應該是紅色的LEAVE".

在 Firefox 中,當您將文件拖到文本上時會觸發(fā) LEAVE 事件.

In firefox, the LEAVE event is triggered when you drag the file over text.

推薦答案

截至 22.0 版,F(xiàn)irefox 仍在這樣做.當您在文本節(jié)點上拖動時,它會觸發(fā)兩種 dragenterdragleave 事件:一種是事件目標和relatedTarget 都是文本節(jié)點的父元素,另一種是其中 target 是父元素,relatedTarget 是實際的文本節(jié)點(甚至不是正確的 DOM 元素).

As of version 22.0 Firefox is still doing this. When you drag over a text node it fires two kinds of dragenter and dragleave events: one where the event target and relatedTarget are BOTH the parent element of the text node, and another where the target is the parent element and the relatedTarget is the actual text node (not even a proper DOM element).

解決方法是在 dragenterdragleave 處理程序中檢查這兩種事件并忽略它們:

The workaround is just to check for those two kinds of events in your dragenter and dragleave handlers and ignore them:

try {
    if(event.relatedTarget.nodeType == 3) return;
} catch(err) {}
if(event.target === event.relatedTarget) return;

我使用 try/catch 塊來檢查 nodeType,因為偶爾會從文檔外部(例如在其他 iframe 中)觸發(fā)事件(莫名其妙地),并且嘗試訪問它們的 nodeType 會引發(fā)權限錯誤.

I use a try/catch block to check the nodeType because occasionally events fire (inexplicably) from outside the document (eg. in other iframes) and trying to access their nodeType throws a permissions error.

以下是實現(xiàn):http://jsfiddle.net/9A7te/

這篇關于Firefox 在文本上拖動時觸發(fā) dragleave的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認為文檔“準備好之前,如何讓我的 jasmine 測試裝置加載?) - IT屋-程序員軟件開發(fā)技術
What do jasmine runs and waitsFor actually do?(jasmine 運行和等待實際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對鏈式方法進行單元測試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
主站蜘蛛池模板: 久久久精品日本 | 91视频亚洲 | 日本黄色免费片 | 一级做a爰片性色毛片视频停止 | www午夜视频| 欧美日韩亚洲三区 | 精品欧美| 精品久久久久久久久久久下田 | 久久视频精品 | 国产亚洲精品成人av久久ww | 国产人免费人成免费视频 | 免费同性女女aaa免费网站 | 一区二区在线看 | 播放一级黄色片 | 99久久免费精品国产男女高不卡 | 欧美又大粗又爽又黄大片视频 | 九九久久久 | 国产日韩精品在线 | 日本韩国电影免费观看 | 一区二区三区免费观看 | 国产三级在线观看播放 | 有码一区 | 久久国产精品一区二区三区 | 中国一级特黄真人毛片免费观看 | 亚洲综合久久精品 | 亚洲精品欧美一区二区三区 | 亚洲精品中文字幕在线观看 | 亚洲人人舔人人 | 欧美精品一区二区三区在线播放 | 欧美一区二区三区在线观看 | 99精品视频一区二区三区 | 久草精品在线 | 日本黄色大片免费 | 久久aⅴ乱码一区二区三区 亚洲欧美综合精品另类天天更新 | 久久久久国产一区二区三区 | 91精品国产乱码久久久久久久久 | 久久久久精 | 欧美日韩国产精品一区 | 欧美日韩免费一区二区三区 | 一本大道久久a久久精二百 国产成人免费在线 | 久久国产欧美日韩精品 |