简体   繁体   English

D3js缩放不起作用

[英]D3js zoom does not work

I can not make zoom work. 我无法进行缩放工作。 Tried everything. 尝试了一切。
My goal: 我的目标:

  • zoom on mouse scroll 放大鼠标滚动
  • drag the tree by a mouse 用鼠标拖动树

The code is here: 代码在这里:

svg = d3.select("#tree-container")
        .append("svg").attr("width", width)
        .attr("height", height)
        .call(zm = d3.behavior.zoom().scaleExtent([1, 3]).on("zoom", redraw))
        .append("g")
        .attr("transform", "translate(" + 350 + "," + 20 + ")");

jsFiddle 的jsfiddle
PS sorry for spaggeti code PS抱歉spaggeti代码

It's the declaration of your redraw function that causes the problem -- if you declare it as a function, it works fine: 这是您的redraw函数的声明导致问题 - 如果您将其声明为函数,它可以正常工作:

function redraw() {
  // etc
}

Complete example here . 在这里完成示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM