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
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 128 128" height="128" width="128" preserveAspectRatio="xMinYMin">
<defs>
<radialGradient gradientUnits="userSpaceOnUse" cx="-12" cy="-12" r="20" fx="-12" fy="-12" id="shine">
<stop offset="0" stop-color="white" stop-opacity="0.7"/>
<stop offset="1" stop-color="white" stop-opacity="0"/>
</radialGradient>
<radialGradient gradientUnits="userSpaceOnUse" fy="0" fx="0" cx="0" cy="0" r="20" id="grad">
<stop offset="0" stop-color="yellow"/>
<stop offset=".75" stop-color="yellow"/>
<stop offset=".95" stop-color="#ee0"/>
<stop offset="1" stop-color="#e8e800"/>
</radialGradient>
</defs>
<rect x="0" y="0" width="128" height="128" style="fill:#0f0;stroke-width:2;stroke:#000"/>
<circle r="63" cx="64" cy="64" style="fill:url(#grad);stroke-width:1;stroke:#000"/>
<circle r="63" cx="64" cy="64" fill="url(#shine)"/>
<text x="64" y="64" style="text-anchor:middle">Some Text VAVA</text>
</svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment