English 中文(简体)
流动和交叉借款人
原标题:mousemove and cross-browser e.which

我需要知道,每起 mo花事件都会引起哪些 mo用钥匙。


    getMouseCode: function(e) {
        e = e || window.event;
        if (!e.which && e.button) {
            if      (e.button & 1) e.which = 1;
            else if (e.button & 4) e.which = 2;
            else if (e.button & 2) e.which = 3;
        };
        return e.which;
    },

但是,这只是在神学院和IE7-8学校进行。 IE9 debugger总称:e.button == 页: 1 1. 在几处 de后,我发现这个窗口。 IE9的活动含有正确的价值,因此我放弃了这一价值。


e = window.event || e;

这对Safat &、Air、Adre、Serge和Sercury来说也是如此。 事件物体。

问题回答

我在调查一个相关问题时正在研究这一问题。 我认为,我的问题是,我需要利用单独的职能来处理<条码>onclick<>/code>和<条码>onmouseover事件。

我发现,在使用歌剧、Safari和PireFox时,在未点击 mo子的情况下, mo子的“财产”被定为1。

虽然这一答案可能很晚,但我确信,它将帮助今后的人。 在寻找这一交叉浏览器特征时,我 st倒了这个问题,最初却忽视了这个问题。 我回头来回答那些步行走的人。

首先,一些知识。 我发现,这个网站非常有用,因为所有交叉浏览器问题(大多数)都得到了解决,并为您的判断作了规定(当我们的发展者需要绘制图表,说明浏览器如何工作时,我很困难)。

rel=“nofollow”http://unixpa.com/js/mouse.html

在这一页上,在底部附近,你会发现一个蓝色链接,它说“这里有各种 mo子进行测试”,比你看一看一刀。 这涉及你们的 mo或 mo。 如果你正确点击和查看这个地点的来源,你就会发现一个具有2个功能的文字标签,即上述链接,以及防止事件发生违约的固定功能,或者说,尽管并非在所有情况下都需要,但可以了解情况。

第二个知识来源于另一个网站,为我们提供了如何掌握摩擦和 events事件的见解。

rel=“nofollow”http://www.javascriptkit.com/javatutors/onmousewheel.shtml

为了把这一切放在一席之地,我们基本上有以下几点。

function GetMouseButton(e) {
    // Normalize event variable
    var e = window.event || e;
    // Set button to initially not recognized (or false if you need to to be)
    var button =  Not Recognized ;

    // Check if this is a button push event
    if(e.type ==  mousedown  || e.type ==  mouseup ) {
        if (e.which == null) {
            // Check if IE, if so, what e.button was pressed
            button = (e.button < 2) ? "Left" :
                ((e.button == 4) ? "Middle" : "Right");
        } else {
            // All other browsers, what e.which was pressed
            button = (e.which < 2) ? "Left" :
                ((e.which == 2) ? "Middle" : "Right");
        }
    } else {
        // If this is not a button push event, then we get the direction
        var direction = e.detail ? e.detail * (-120) : e.wheelDelta;
        // And name the direction as a  button 
        switch(direction) {
            case 120: // Browsers use different variants of these
            case 240: 
            case 360: 
                button = "Middle Scroll Up";
            break;
            case -120:
            case -240:
            case -360:
                button = "Middle Scroll Down";
            break;
        }
    }

    alert(button);
}

/* Simple Bind function (like jQuery s for example) */
function Bind(elem, type, eventHandle) {
    if (elem == null || elem == undefined) return;
    if ( elem.addEventListener ) {
        elem.addEventListener( type, eventHandle, false );
    } else if ( elem.attachEvent ) {
        elem.attachEvent( "on" + type, eventHandle );
    } else {
        elem["on"+type]=eventHandle;
    }
}

/* Bind your mousedown / mouseup to the window, as well as the mousewheel */
Bind(window,  mousedown , GetMouseButton);
Bind(window,  mouseup , GetMouseButton);

/* One of FireFox s browser versions doesn t recognize mousewheel,
 * we account for that in this line
 */
var MouseWheelEvent = 
(/Firefox/i.test(navigator.userAgent))? "DOMMouseScroll" : "mousewheel";

Bind(window, MouseWheelEvent, GetMouseButton);

<><>>>> 为节省一段时间[和知道,如果你不关心研究这些联系],你可以在以下支部看到一个工作榜样:。

http://jsfiddle.net/BNefn/

EDIT I should have also said, that since you need to know this on every mousemove event, you can simply store the resulting button name and event type (down or up), and then recall that variables information during your mousemove event. If you have a variable for each of these "buttons" you can then see which button is pressed and which isn t, and clear the variables that are pressed on mouseup.





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签