首页 > 语言 > JavaScript > 正文

一个很酷的拖动层的js类,兼容IE及Firefox

2024-05-06 14:15:04
字体:
来源:转载
供稿:网友

自己优化修改了网上的一个JS拖动类,增加了拖动时显示半透明的特效。 //www.Vevb.com/article/16122.htm
注意,本文类中的Cminfo类请 查看:
//www.Vevb.com/article/18760.htm

代码如下:
//*********************************移动层 函数 开始*******************************************
//生成拖动层很简单,只需要(参数之一如果是数组表示局部拖动,arr[0]表示拖动层,arr[1]表示整体)
//new divDrag(['test'], [getObject('test31'),getObject('test3')], getObject('test1') ,getObject('test2') ,[getObject('test41'),getObject('test4')]);
//记得有拖动属性的层position:absolute;
Array.prototype.extend = function(C){for(var B=0,A=C.length;B<A;B++){this.push(C[B]);}return this;}
function divDrag()
{
    var A,B,gCn;
    var zIndex = 1;
    this.dragStart = function(e)
    {
        e = e||window.event;
        if((e.which && (e.which!=1))||(e.button && (e.button!=1))){return;}
        var pos = this.gPos;
        gCn = this.parent||this;
        if(document.defaultView)
        {
            _top = document.defaultView.getComputedStyle(gCn,null).getPropertyValue("top");
            _left = document.defaultView.getComputedStyle(gCn,null).getPropertyValue("left");
        }
        else
        {
            if(gCn.currentStyle)
            {
                _top = gCn.currentStyle["top"];
                _left = gCn.currentStyle["left"];
            }
        }
        pos.ox = (e.pageX||(e.clientX+document.documentElement.scrollLeft))-parseInt(_left);
        pos.oy = (e.pageY||(e.clientY+document.documentElement.scrollTop))-parseInt(_top);
        if(!!A)
        {
            if(document.removeEventListener)
            {

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选