嗨我正在嘗試縮放和平移一些圖像。我從這個鏈接中得到了例子:http://bl.ocks.org/mbostock/3681006主要的區別是他們繪製的形狀不是圖像。這裏有一個劇本,我做了什麼使用d3.js縮放平移圖像
https://jsfiddle.net/t1gqg1m6/1/
var width = 960,
height = 500;
var randomX = d3.random.normal(width/2, 80),
randomY = d3.random.normal(height/2, 80);
var data = d3.range(2000).map(function() {
return [
randomX(),
randomY()
];
});
var x = d3.scale.linear()
.domain([0, width])
.range([0, width]);
var y = d3.scale.linear()
.domain([0, height])
.range([height, 0]);
var canvas = d3.select("canvas")
.attr("width", width)
.attr("height", height)
.call(d3.behavior.zoom().x(x).y(y).scaleExtent([1, 8]).on("zoom", zoom))
.node().getContext("2d");
function zoom() {
canvas.clearRect(0, 0, width, height);
draw();
}
var img = new Image();
img.onload = function() {
function draw(){
for(var i=0;i<=500;i+=50){
canvas.drawImage(img, i, 10, 50, 40);
}
}
draw();
}
img.src = "http://static.dnaindia.com/sites/default/files/styles/half/public/2016/04/02/444652-google-photos-emoji-google-image-search-using-emoji-coolkengzz-shutterstock.jpg?itok=b1lBccFF";
,如果有人可以幫助將是巨大的。先謝謝你。
您的問題是? –