Sfortunatamente, modificando statali o strato impedisce trascinabili oggetti non trascinabile. La soluzione di zoom di Duopixel è buona, ma preferisco impostarla per il livello di stage, non a livello di livello.
La sua è la mia soluzione
var stage = new Kinetic.Stage({
container : 'container',
width: $("#container").width(),
height: $("#container").height(),
});
var layer = new Kinetic.Layer();
//layer.setDraggable("draggable");
var center = { x:stage.getWidth()/2, y: stage.getHeight()/2};
var circle = new Kinetic.Circle({
x: center.x-100,
y: center.y,
radius: 50,
fill: 'green',
draggable: true
});
layer.add(circle);
layer.add(circle.clone({x: center.x+100}));
// zoom by scrollong
document.getElementById("container").addEventListener("mousewheel", function(e) {
var zoomAmount = e.wheelDeltaY*0.0001;
stage.setScale(stage.getScale().x+zoomAmount)
stage.draw();
e.preventDefault();
}, false)
// pan by mouse dragging on stage
stage.on("dragstart dragmove", function(e) {window.draggingNode = true;});
stage.on("dragend", function(e) { window.draggingNode = false;});
$("#container").on("mousedown", function(e) {
if (window.draggingNode) return false;
if (e.which==1) {
window.draggingStart = {x: e.pageX, y: e.pageY, stageX: stage.getX(), stageY: stage.getY()};
window.draggingStage = true;
}
});
$("#container").on("mousemove", function(e) {
if (window.draggingNode || !window.draggingStage) return false;
stage.setX(window.draggingStart.stageX+(e.pageX-window.draggingStart.x));
stage.setY(window.draggingStart.stageY+(e.pageY-window.draggingStart.y));
stage.draw();
});
$("#container").on("mouseup", function(e) { window.draggingStage = false });
stage.add(layer);
http://jsfiddle.net/bighostkim/jsqJ2/
Funziona alla grande tranne in IE9. Avresti qualche idea sul perché? La console di debug non genera alcun errore ... – Legend
Sembra che funzioni se uso 'e.wheelDelta' invece di' e.wheelDeltaY'. Qualche idea del perché? – Legend
Penso che IE usi il deltaY. Lo zoom della rotellina del mouse era solo un esempio, se hai intenzione di tenerlo, dovresti usare uno shim che compensi la differenza nelle implementazioni del browser come https://github.com/cobbweb/jquery-mousewheel – Duopixel