缩放在5.0.0中不像版本bevor那样有效

时间:2014-01-17 09:20:11

标签: zoom kineticjs

我遇到的问题是新5.0.0版本中的缩放功能不像bevor一样缩放。

我使用以下测试测试了新版本5.0.0:

请参阅此jsfiddle

我将.js文件更改为:

http://d3lp1msu2r81bx.cloudfront.net/kjs/js/lib/kinetic-v5.0.0.min.js

并对新的缩放功能进行更改:

ui.stage.setScale(newscale); --> ui.stage.setScale({x:newscale,y:newscale});

错误是5.0.0中的zoompoint是左上角而不是mousepoint liek bevor。

有什么建议吗?

1 个答案:

答案 0 :(得分:3)

如果您使用的是kinetic.jsv5.0.0

,请更改此项

您还可以查看Kinetic.jsv5.0.0

中所做的所有更改
ui.stage.setScale(newscale); --> ui.stage.setScale({x:newscale,y:newscale});

ui.stage.setOffset(ui.origin.x,ui.origin.y); --> ui.stage.setOffset({x: ui.origin.x, y: ui.origin.y});

或 应用以下代码:

var ui = {
    stage: null,
    scale: 1,
    zoomFactor: 1.1,
    origin: {
        x: 0,
        y: 0
    },
    zoom: function(event) {
        event.preventDefault();
        var evt = event.originalEvent,
            mx = evt.clientX - ui.stage.getX(),
            my = evt.clientY - ui.stage.getY(),
            zoom = (ui.zoomFactor - (evt.wheelDelta < 0 ? 0.2 : 0)),
            newscale = ui.scale * zoom;

        ui.origin.x = mx / ui.scale + ui.origin.x - mx / newscale;
        ui.origin.y = my / ui.scale + ui.origin.y - my / newscale;

        ui.stage.setOffset({x: ui.origin.x, y: ui.origin.y});
        ui.stage.setScale({x: newscale, y: newscale});
        ui.stage.draw();

        ui.scale *= zoom;
    }
};

$(function() {
    var width = $(document).width() - 2,
        height = $(document).height() - 5;
    var stage = ui.stage = new Kinetic.Stage({
        container: 'container',
        width: width,
        height: height,
        draggable: true
    });
    var layer = new Kinetic.Layer();

    var box1 = ui.box = new Kinetic.Circle({
        x: 50,
        y: 50,
        radius: 50,
        fill: '#00D200',
        stroke: 'black',
        strokeWidth: 2,
        draggable: true
    });

    var box2 = ui.box = new Kinetic.Circle({
        x: 150,
        y: 150,
        radius: 50,
        fill: 'red',
        stroke: 'black',
        strokeWidth: 2,
        draggable: true
    });

    // add cursor styling
    box1.on('mouseover', function() {
        document.body.style.cursor = 'pointer';
    });
    box1.on('mouseout', function() {
        document.body.style.cursor = 'default';
    });

    // add cursor styling
    box2.on('mouseover', function() {
        document.body.style.cursor = 'pointer';
    });
    box2.on('mouseout', function() {
        document.body.style.cursor = 'default';
    });

    layer.add(box1);
    layer.add(box2);
    stage.add(layer);

    $(stage.content).on('mousewheel', ui.zoom);
});

JSFiddle:http://jsfiddle.net/bijaybhandari1989/6J8F5/4/