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

Firefox 中的拖動(dòng)事件沒有 e.clientX 或 e.clientY

No e.clientX or e.clientY on drag event in Firefox(Firefox 中的拖動(dòng)事件沒有 e.clientX 或 e.clientY)
本文介紹了Firefox 中的拖動(dòng)事件沒有 e.clientX 或 e.clientY的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

限時(shí)送ChatGPT賬號(hào)..

我已經(jīng)使用 Angular 中的指令實(shí)現(xiàn)了一個(gè)簡(jiǎn)單的拖放系統(tǒng).它在 Chrome 中運(yùn)行良好,但 Firefox 不會(huì)在拖動(dòng)事件上公開 event.clientX、event.clientY 屬性(他們只是拒絕修復(fù)它).

所以我正在尋找一個(gè)很好的替代方法來在拖動(dòng)事件中公開這些屬性:x,y 坐標(biāo)是拖動(dòng)事件的視覺反饋所必需的.

代碼在(在 Chrome 和 FF 中測(cè)試).

對(duì)js的改動(dòng):

.directive('mpDrag', function($timeout, $window, $document) {//保持坐標(biāo)私有和//在指令的所有實(shí)例之間共享變量鼠標(biāo)X,鼠標(biāo)Y;$document.on("dragover", function(event){mouseX = event.originalEvent.clientX;mouseY = event.originalEvent.clientY;})返回 {...鏈接:函數(shù)($范圍,元素,屬性){...$超時(shí)(函數(shù)(){....on('拖動(dòng)', function(e) {//這里直接使用mouseX,mouseY//(順便說一句.你應(yīng)該以不同的方式檢測(cè)何時(shí)隱藏元素)console.log(mouseX, mouseY);如果(e.originalEvent.clientX){el.css({'頂部':鼠標(biāo)Y,左":鼠標(biāo)X});} 別的 {el.css('顯示', '無');}});});}};})

I've implemented a simple drag and drop system using directives in Angular. It works fine in Chrome, but Firefox doesn't expose event.clientX, event.clientY properties on drag event (They just refuse to fix it).

So I'm looking for a good alternative to expose these properties on drag event: the x,y coordinates are needed for visual feedback on drag event.

Code is here - check out in Chrome and Firefox to see the problem.

In Chrome, drag an item in the folders, you'll have the same item displayed as visual feedback following the mouse, not in Firefox (because Firefox doesn't support e.clientX and e.clientY in the drag event).

the problem is here (beginning line 45):

.on('drag', function(e) {
    if (e.originalEvent.clientX) {
        el.css({
           'top': e.originalEvent.clientY + 10,
           'left': e.originalEvent.clientX + 10
        });
    } else {
        el.css('display', 'none');
    }
});

So how can I get the mouse position on screen during a drag event, in Firefox (the angular way, I mean with directives, no global variable, or whatever)?

解決方案

You can hook up to dragover on document -- clientX and clientY are exposed there. Use functional closure to not populating global scope. Here is updated PLNKR (tested in Chrome and FF).

Changes to js:

.directive('mpDrag', function($timeout, $window, $document) {

    // keeping coordinates private and 
    // shared among all instances of the directive
    var mouseX, mouseY;

    $document.on("dragover", function(event){
      mouseX = event.originalEvent.clientX;
      mouseY = event.originalEvent.clientY;
    })

    return {
      ...
      link: function($scope, element, attrs) {
        ...
        $timeout(function() {

        ...
            .on('drag', function(e) {
              // just use mouseX, mouseY directely here
              // (btw. you should detect differently when to hide the element)
              console.log(mouseX, mouseY); 
              if (e.originalEvent.clientX) {
                el.css({
                  'top': mouseY,
                  'left': mouseX
                });
              } else {
                el.css('display', 'none');
              }
            });
        });
      }
    };
  })

這篇關(guān)于Firefox 中的拖動(dòng)事件沒有 e.clientX 或 e.clientY的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How can I get my jasmine tests fixtures to load before the javascript considers the document to be quot;readyquot;?(在 javascript 認(rèn)為文檔“準(zhǔn)備好之前,如何讓我的 jasmine 測(cè)試裝置加載?) - IT屋-程序員軟件開發(fā)技術(shù)
What do jasmine runs and waitsFor actually do?(jasmine 運(yùn)行和等待實(shí)際上是做什么的?)
How to provide mock files to change event of lt;input type=#39;file#39;gt; for unit testing(如何提供模擬文件來更改 lt;input type=filegt; 的事件用于單元測(cè)試)
How to unit test a chained method using Jasmine(如何使用 Jasmine 對(duì)鏈?zhǔn)椒椒ㄟM(jìn)行單元測(cè)試)
How do I inject $rootScope into an AngularJS unit test?(如何將 $rootScope 注入 AngularJS 單元測(cè)試?)
Jasmine - How to spy on a function call within a function?(Jasmine - 如何監(jiān)視函數(shù)中的函數(shù)調(diào)用?)
主站蜘蛛池模板: 九九热在线观看 | 欧美精品一区二区在线观看 | 日韩在线视频一区 | 国产精品久久久久无码av | 欧美一级网站 | 久久国产区 | 久久1区| 成人av网站在线观看 | 久久久久亚洲 | 亚洲免费视频一区 | 欧美激情久久久 | 91动漫在线观看 | www.久久 | 亚洲国产免费 | 亚洲精品久久久久久一区二区 | 成人激情视频 | 中文日韩在线视频 | 中文字幕日韩av | 在线视频亚洲 | 九九亚洲 | 亚洲视频在线一区 | 亚洲成人一级 | 日韩中文电影 | 久久久久久黄 | 亚洲91视频 | 超碰导航 | 操操日 | 日韩av最新网址 | 亚洲一区在线播放 | 国产一级片免费看 | 男女深夜网站 | 亚州成人 | 丁香婷婷综合激情五月色 | 亚洲激情网站 | 国产精品久久久久久久久图文区 | 亚洲欧美国产毛片在线 | 久久综合九色综合欧美狠狠 | 亚洲精品一区二区三区在线 | 免费一级做a爰片久久毛片潮喷 | 成年男女免费视频网站 | 免费在线h视频 |