drag plugin
This commit is contained in:
parent
d1a13c9b0b
commit
02f6fcfd13
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,14 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head lang="en">
|
||||
<meta charset="UTF-8">
|
||||
<title></title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container"></div>
|
||||
<a href="https://github.com/AlloyTeam/omi" target="_blank" style="position: absolute; right: 0; top: 0;">
|
||||
<img src="../../asset/github.png" alt="" />
|
||||
</a>
|
||||
<script src="bundler.js"></script>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,34 @@
|
|||
import OmiDrag from './omi-drag.js';
|
||||
|
||||
OmiDrag.init();
|
||||
|
||||
|
||||
class App extends Omi.Component {
|
||||
constructor(data) {
|
||||
super(data);
|
||||
}
|
||||
|
||||
render() {
|
||||
return `
|
||||
<div>
|
||||
<div omi-drag class="test">Drag Me<div>
|
||||
</div>
|
||||
`;
|
||||
|
||||
}
|
||||
|
||||
style(){
|
||||
return `
|
||||
.test{
|
||||
width:100px;
|
||||
height:100px;
|
||||
color:white;
|
||||
line-height:90px;
|
||||
text-align:center;
|
||||
background-color:#00BFF3;
|
||||
}
|
||||
`
|
||||
}
|
||||
}
|
||||
|
||||
Omi.render(new App(),"#container");
|
|
@ -0,0 +1,58 @@
|
|||
;(function () {
|
||||
|
||||
var OmiDrag = {};
|
||||
var Omi = typeof require === 'function'
|
||||
? require('../../src/index.js')
|
||||
: window.Omi;
|
||||
|
||||
OmiDrag.init = function(){
|
||||
Omi.extendPlugin('omi-drag',function(dom, instance){
|
||||
dom.style.cursor='move';
|
||||
var isMouseDown = false,
|
||||
preX = preY = currentX = currentY = null,
|
||||
translateX = 0,
|
||||
translateY = 0;
|
||||
|
||||
dom.addEventListener('mousedown',function(evt){
|
||||
isMouseDown = true;
|
||||
preX = evt.pageX;
|
||||
preY = evt.pageY;
|
||||
evt.stopPropagation();
|
||||
},false);
|
||||
|
||||
window.addEventListener('mousemove',function(evt){
|
||||
if(isMouseDown){
|
||||
currentX = evt.pageX;
|
||||
currentY = evt.pageY;
|
||||
|
||||
if(preX != null){
|
||||
translateX += currentX - preX;
|
||||
translateY += currentY - preY;
|
||||
dom.style.transform = 'translateX('+translateX+'px) translateY('+translateY+'px)';
|
||||
}
|
||||
preX = currentX;
|
||||
preY = currentY;
|
||||
evt.preventDefault();
|
||||
}
|
||||
},false);
|
||||
|
||||
window.addEventListener('mouseup',function(){
|
||||
isMouseDown = false;
|
||||
preX = preY = currentX = currentY = null;
|
||||
},false);
|
||||
});
|
||||
}
|
||||
|
||||
OmiDrag.destroy = function(){
|
||||
delete Omi.plugins['omi-drag'];
|
||||
};
|
||||
|
||||
if (typeof exports == "object") {
|
||||
module.exports = OmiDrag;
|
||||
} else if (typeof define == "function" && define.amd) {
|
||||
define([], function(){ return OmiDrag });
|
||||
} else {
|
||||
window.OmiDrag = OmiDrag;
|
||||
}
|
||||
|
||||
})();
|
|
@ -10,7 +10,7 @@
|
|||
"curd": "webpack -w",
|
||||
"hello": "webpack -w",
|
||||
"loop": "webpack -w",
|
||||
"finger": "webpack -w",
|
||||
"plugin": "webpack -w",
|
||||
"order": "webpack -w",
|
||||
"timer": "webpack -w",
|
||||
"communication": "webpack -w",
|
||||
|
|
Loading…
Reference in New Issue