Skip to content

Instantly share code, notes, and snippets.

@Herst
Last active August 11, 2017 00:03
Show Gist options
  • Save Herst/da06ec62b68939d9b4a67e9feed6ccf3 to your computer and use it in GitHub Desktop.
Save Herst/da06ec62b68939d9b4a67e9feed6ccf3 to your computer and use it in GitHub Desktop.
Wibbly-wobbly behavior in Chrome (Blink)
license: gpl-3.0

Increase the zoom factor for a stronger effect on Google Chrome.

The widths of the <image> element inside the SVG is being changed continously but since preserveAspectRatio is set to xMinYMin (i.e. aspect ratio will be preserved and image will stick to topleft corner) it should have no effect. It does have an effect though in Mozilla Firefox (Gecko) as of version 54 and Google Chrome 61 (Blink). In latter the effect is even more pronounced when zoomed in.

(On a side note, the preserveAspectRatio attribute is set inside the SVG and on the image element, in Chrome latter does not override former if SVG images are referenced because of http://crbug.com/499373. Since in this example both attributes are set to the same value it makes no difference.)

<!DOCTYPE html>
<meta charset="utf-8">
<body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("body").append("svg").attr("width", "100%").attr("height", "100%").append("g");
var img = svg
.append("image")
.attr("xlink:href", "referenced.svg")
.attr("preserveAspectRatio", "xMinYMin") // http://crbug.com/499373 --> in Blink only value inside SVG matters
.attr("width", 128)
.attr("height", 128);
var rect = svg.append("rect").attr("opacity", .3).attr("fill", "yellow").attr("width", 128).attr("height", 128);
(function update() {
d3.selectAll(img.nodes().concat(rect.nodes()))
.attr("width", 128)
.transition()
.duration(10000)
.ease(d3.easeLinear)
.attr("width", 192)
.on("end", update);
})();
</script>
</body>
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment