2.精通前端系列技術之seajs模組化使工作更簡單(二)

來源:互聯網
上載者:User

標籤:

drag.js

// JavaScript Document//B開發define(function(require,exports,module){        function drag(obj){        var disX = 0;        var disY = 0;                obj.onmousedown = function(ev){                        var ev = ev || window.event;            disX = ev.clientX - obj.offsetLeft;            disY = ev.clientY - obj.offsetTop;                        document.onmousemove = function(ev){                var ev = ev || window.event;                                var L = ev.clientX - disX;                var T = ev.clientY - disY;                                //L = require(‘./range.js‘).range(L , document.documentElement.clientWidth - obj.offsetWidth , 0);                //T = require(‘./range.js‘).range(T , document.documentElement.clientHeight - obj.offsetHeight , 0);                                obj.style.left = L + ‘px‘;                obj.style.top = T + ‘px‘;            };                        document.onmouseup = function(){                document.onmousemove = null;                document.onmouseup = null;            };                        return false;                    };            }        exports.drag = drag;    });

main.js

// JavaScript Document//A開發define(function(require,exports,module){        var oInput = document.getElementById(‘input1‘);    var oDiv1 = document.getElementById(‘div1‘);    var oDiv2 = document.getElementById(‘div2‘);    var oDiv3 = document.getElementById(‘div3‘);        require(‘./drag.js‘).drag(oDiv3);        oInput.onclick = function(){                oDiv1.style.display = ‘block‘;                require(‘./scale.js‘).scale(oDiv1,oDiv2);            };    });

range.js

// JavaScript Documentdefine(function(require,exports,module){        function range(val , max , min){                if( val > max ){            return max;        }        else if( val < min ){            return min;        }        else{            return val;        }            }        exports.range = range;    });

scale.js

// JavaScript Document//C開發define(function(require,exports,module){        function scale(obj1,obj2){                var downX = 0;        var downY = 0;        var downW = 0;        var downH = 0;                obj2.onmousedown = function(ev){            var ev = ev || window.event;            downX = ev.clientX;            downY = ev.clientY;            downW = obj1.offsetWidth;            downH = obj1.offsetHeight;                        document.onmousemove = function(ev){                var ev = ev || window.event;                                var W =  ev.clientX - downX + downW;                var H = ev.clientY - downY + downH;                                W = require(‘./range.js‘).range(W , 500 , 100);                H = require(‘./range.js‘).range(H , 500 , 100);                                obj1.style.width = W + ‘px‘;                obj1.style.height = H + ‘px‘;            };                        document.onmouseup = function(){                document.onmousemove = null;                document.onmouseup = null;            };                        return false;                    };            }        exports.scale = scale;    });

index.html

<!DOCTYPE HTML><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>無標題文檔</title><style>#div1{ width:200px; height:200px; background:red; position:absolute; display:none;}#div2{ width:30px; height:30px; background:yellow; position:absolute; right:0; bottom:0;}#div3{ width:100px; height:100px; background:blue; position:absolute; right:0; top:0;}</style><script src="../sea/sea.js"></script><script>//A開發seajs.use(‘./main.js‘);</script></head><body><input type="button" value="彈窗" id="input1"><div id="div1">    <div id="div2"></div></div><div id="div3"></div></body></html>

 

2.精通前端系列技術之seajs模組化使工作更簡單(二)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.