qin
2024-04-01 d1a50163e4d445bc8451cf68cf0791caf7c410e0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
 
$.fn.extend({
        //---元素拖动插件 
    dragging:function(data){   
        var $this = $(this);
        var xPage;
        var yPage;
        var X;//
        var Y;//
        var xRand = 0;//
        var yRand = 0;//
        var father = $this.parent();
        var defaults = {
            move : 'both',
            randomPosition : true ,
            hander: 1,
            notelement:'.bf-container'
        }
        var opt = $.extend({},defaults,data);
        var movePosition = opt.move;
        var random = opt.randomPosition;
        
        var hander = opt.hander;
        var notelement = opt.notelement;
        if(hander == 1){
            hander = $this; 
        }else{
            hander = $this.find(opt.hander);
        }
        
            
        //---初始化
        father.css({"position":"relative","overflow":"hidden"}); 
        $this.css({"position":"absolute"});
        hander.css({"cursor":"move"});
 
        var faWidth = father.width();
        var faHeight = father.height();
        var thisWidth = $this.width()+parseInt($this.css('padding-left'))+parseInt($this.css('padding-right'));
        var thisHeight = $this.height()+parseInt($this.css('padding-top'))+parseInt($this.css('padding-bottom'));
        
        var mDown = false;//
        var positionX;
        var positionY;
        var moveX ;
        var moveY ;
        
        if(random){
            $thisRandom();
        }
        function $thisRandom(){ //随机函数
            $this.each(function(index){
                var randY = parseInt(Math.random()*(faHeight-thisHeight));///
                var randX = parseInt(Math.random()*(faWidth-thisWidth));///
                if(movePosition.toLowerCase() == 'x'){
                    $(this).css({
                        left:randX
                    });
                }else if(movePosition.toLowerCase() == 'y'){
                    $(this).css({
                        top:randY
                    });
                }else if(movePosition.toLowerCase() == 'both'){
                    $(this).css({
                        top:randY,
                        left:randX
                    });
                }
                
            });    
        }
        
        hander.mousedown(function (e) {
            //console.log(notelement)
            //father.children().css({"zIndex":"1"});//原始
            father.children().not(notelement).css({ "zIndex": "1" });//适应在BIM上拖动  .bf-container是BIM模式所在的box
            $this.css({"zIndex":"2"});
            mDown = true;
            X = e.pageX;
            Y = e.pageY;
            positionX = $this.position().left;
            positionY = $this.position().top;
            return false;
        });
            
        $(document).mouseup(function(e){
            mDown = false;
        });
            
        $(document).mousemove(function(e){
            xPage = e.pageX;//--
            moveX = positionX+xPage-X;
            
            yPage = e.pageY;//--
            moveY = positionY+yPage-Y;
            
            function thisXMove(){ //x轴移动
                if(mDown == true){
                    $this.css({"left":moveX});
                }else{
                    return;
                }
                if(moveX < 0){
                    $this.css({"left":"0"});
                }
                if(moveX > (faWidth-thisWidth)){
                    $this.css({"left":faWidth-thisWidth});
                }
                return moveX;
            }
            
            function thisYMove(){ //y轴移动
                if(mDown == true){
                    $this.css({"top":moveY});
                }else{
                    return;
                }
                if(moveY < 0){
                    $this.css({"top":"0"});
                }
                if(moveY > (faHeight-thisHeight)){
                    $this.css({"top":faHeight-thisHeight});
                }
                return moveY;
            }
 
            function thisAllMove(){ //全部移动
                if(mDown == true){
                    $this.css({"left":moveX,"top":moveY});
                }else{
                    return;
                }
                if(moveX < 0){
                    $this.css({"left":"0"});
                }
                if(moveX > (faWidth-thisWidth)){
                    $this.css({"left":faWidth-thisWidth});
                }
 
                if(moveY < 0){
                    $this.css({"top":"0"});
                }
                if(moveY > (faHeight-thisHeight)){
                    $this.css({"top":faHeight-thisHeight});
                }
            }
            if(movePosition.toLowerCase() == "x"){
                thisXMove();
            }else if(movePosition.toLowerCase() == "y"){
                thisYMove();
            }else if(movePosition.toLowerCase() == 'both'){
                thisAllMove();
            }
        });
    }
});