mirror of
https://github.com/hiloteam/Hilo.git
synced 2025-12-08 20:35:59 +00:00
71 lines
2.4 KiB
HTML
71 lines
2.4 KiB
HTML
<!doctype html>
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8">
|
||
<meta name="viewport" content="user-scalable=no, width=device-width, minimum-scale=1, maximum-scale=1" />
|
||
<title>drag - Hilo Example</title>
|
||
<link rel="stylesheet" type="text/css" href="css/style.css">
|
||
<script type="text/javascript" src="../build/standalone/hilo-standalone.min.js"></script>
|
||
<script type="text/javascript" src="../build/flash/hilo-flash.min.js" data-auto="true"></script>
|
||
</head>
|
||
<body onload="init();">
|
||
<div id="header">
|
||
<h1>drag</h1>
|
||
<p>通过mix可以让view拥有拖拽功能,支持拖拽范围限制</p>
|
||
</div>
|
||
<div id="game-container"></div>
|
||
<script type="text/javascript" src="js/demo.js"></script>
|
||
<script type="text/javascript">
|
||
function init(){
|
||
//init stage
|
||
var stage = new Hilo.Stage({
|
||
renderType:renderType,
|
||
container: gameContainer,
|
||
width: stageWidth,
|
||
height: stageHeight
|
||
});
|
||
|
||
stage.enableDOMEvent([Hilo.event.POINTER_START, Hilo.event.POINTER_MOVE, Hilo.event.POINTER_END]);
|
||
|
||
//start stage ticker
|
||
var ticker = new Hilo.Ticker(20);
|
||
ticker.addTick(stage);
|
||
ticker.start();
|
||
|
||
var container = new Hilo.Container({
|
||
x:winWidth * .1,
|
||
y:20,
|
||
width:winWidth * .8,
|
||
height:200,
|
||
background:"#f00"
|
||
}).addTo(stage);
|
||
|
||
//create a bitmap
|
||
var bmp = new Hilo.Bitmap({
|
||
image: 'images/fish.png',
|
||
rect: [0, 0, 174, 126],
|
||
x: container.x,
|
||
y: container.y
|
||
}).addTo(stage);
|
||
|
||
//mix drag
|
||
Hilo.util.copy(bmp, Hilo.drag);
|
||
bmp.startDrag([container.x, container.y, container.width - bmp.width, container.height - bmp.height]);
|
||
|
||
bmp.on("dragStart", function(e){
|
||
console.log("dragStart", e.detail.x, e.detail.y);
|
||
});
|
||
bmp.on("dragEnd", function(e){
|
||
console.log("dragEnd", e.detail.x, e.detail.y);
|
||
});
|
||
bmp.on("dragMove", function(e){
|
||
// console.log("dragMove", e.detail.x, e.detail.y);
|
||
});
|
||
|
||
document.ontouchstart = function(e){
|
||
e.preventDefault();
|
||
}
|
||
}
|
||
</script>
|
||
</body>
|
||
</html> |