简体   繁体   English

我怎样才能让这个 globe visualization(svg) 响应不同的屏幕尺寸?

[英]How can I get this globe visualisation(svg) to become responsive to different screen sizes?

Languages: Javascript, HTML and CSS.语言: Javascript、HTML 和 CSS。

Frameworks: D3.js框架: D3.js

link to code: https://observablehq.com/@michael-keith/draggable-globe-in-d3代码链接: https://observablehq.com/@michael-keith/draggable-globe-in-d3

Question:题:

How can I get the globe visualisation to become responsive to different screen sizes?我怎样才能让地球可视化成为响应不同的屏幕尺寸? eg at iphone globe width width = 200px at ipad globe width = 300px例如在 iphone globe width width = 200px 在 ipad globe width = 300px

First What I don't want is to set breakpoints to resize the <svg>首先我不想设置断点来调整<svg>的大小

What I've tried:我试过的:

I've tried using the attributes viewBox and preserveAspectRatio eg我试过使用属性viewBoxpreserveAspectRatio例如

  .attr("viewBox", `0 0 ${width} ${height}`)
  .attr("preserveAspectRatio", "xMinYMin meet")

however, nothing happens.然而,没有任何反应。 my guess might be because of how the height and width are set.我的猜测可能是因为高度和宽度的设置方式。 eg例如

let width = d3.select("#map").node().getBoundingClientRect().width
let height = 500

any ideas are welcome欢迎任何想法

Did you try using viewBox directly on the svg tag, without specifying width or height?您是否尝试在 svg 标签上直接使用 viewBox,而不指定宽度或高度? Your javascript should be able to pick the computed size anyway.无论如何,您的 javascript 应该能够选择计算出的大小。

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

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