Skip to content

Instantly share code, notes, and snippets.

@imagebox
Created February 11, 2021 19:55
Show Gist options
  • Save imagebox/6f7da655d55fc5550eece9469e5b7c15 to your computer and use it in GitHub Desktop.
Save imagebox/6f7da655d55fc5550eece9469e5b7c15 to your computer and use it in GitHub Desktop.
[Responsive SVG with JS] #svg #responsive #js
// enclose svg in div with class svg-container
// in example below, 599/859 is the svg's height/width
$(window).on("resize", function () {
var myWidth = $('.svg-container').width();
var myHeight = (myWidth * 599/859);
$('.svg-container svg').css('width', myWidth + 'px');
$('.svg-container svg').css('height', myHeight + 'px');
}).resize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment