标题:鼠标脱动,IE和FF不兼容
只看楼主
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
结帖率:0
 问题点数:0 回复次数:2 
鼠标脱动,IE和FF不兼容
FF下报错 EventObject.setCapture is not a function

var EventObject = 0, Old_X, New_X;
function button_down(event){//拖动按钮按下事件
    event = event ? event :(window.event ? window.event : null);
    EventObject = event.srcElement ? event.srcElement : event.target;
    Old_X = event.clientX;
    EventObject.setCapture();
    }
function button_move(event){//拖动按钮移动事件
    if(EventObject){
        New_X = event.clientX;
        try{
        var MovePels = EventObject.style.pixelLeft+New_X-Old_X;
        var MaxBound = document.getElementById(EventObject.id+"Box").offsetWidth-EventObject.offsetWidth;
        }
        catch(e){}
        if(EventObject && MovePels <= MaxBound && MovePels >= 0){
            EventObject.style.pixelLeft += New_X-Old_X;
            Old_X = New_X;
            }
        }
    }
function button_up(){//拖动按钮松开事件
    if(EventObject){
        EventObject.releaseCapture();
        EventObject = 0;
        }
    }
搜索更多相关主题的帖子: event 鼠标 EventObject New 拖动 
2008-06-17 10:11
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
得分:0 
有人看没人回啊
2008-06-18 08:54
zhangyao3287
Rank: 2
来 自:黑龙江省
等 级:论坛游民
威 望:2
帖 子:173
专家分:51
注 册:2008-5-25
得分:0 
人还是要靠自己啊


var EventObject = 0, Old_X, New_X;
var isIE = /msie/i.test(navigator.userAgent);
var isFF = /firefox/i.test(navigator.userAgent);
function button_down(event){//拖动按钮按下事件
    event = event ? event :(window.event ? window.event : null);
    EventObject = event.srcElement ? event.srcElement : event.target;
    Old_X = event.clientX;
    document.onmousemove = button_move;
    document.onmouseup = button_up;
    if(isIE)EventObject.setCapture();
    if(isFF)document.addEventListener("mousemove",button_move,true);
    }
function button_move(event){//拖动按钮移动事件
    event = event ? event :(window.event ? window.event : null);
    if(EventObject){
        New_X = event.clientX;
        try{
        var MovePels = parseInt(EventObject.style.left,10)+New_X-Old_X;
        var MaxBound = document.getElementById(EventObject.id+"Box").offsetWidth-EventObject.offsetWidth;
        }
        catch(e){}
        if(EventObject && MovePels <= MaxBound && MovePels >= 0){
            EventObject.style.left = parseInt(EventObject.style.left,10) + New_X-Old_X + "px";
            Old_X = New_X;
            document.getElementById("writer").innerHTML = EventObject.id + ":" +parseInt(EventObject.style.left,10);
            }
        }
    }
function button_up(){//拖动按钮松开事件
    if(EventObject){
        document.onmousemove = null;
        document.onmouseup = null;
        if(isIE)EventObject.releaseCapture();
        if(isFF)document.removeEventListener("mousemove",button_move,true);
        EventObject = 0;
        }
    }
2008-06-18 18:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-219588-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.093455 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved