1

I have this code:

function myClient() {
  if (!(this instanceof arguments.callee)) {
    return new arguments.callee(arguments);
  }
  var self = this;

  this.init = function() {
    self.viewResized();
    self.drawSvg();
  };

  this.viewResized = function () {
      var width = $('body').width(),
          windowHeight = $(window).height(),
          svgCanvasHeight = width * (369.0 / 567.0);
          $('#svg').css({
            'margin-top': 10
          });
    }

  this.drawSvg = function() {

    // ...
}

var myClient;

jQuery(function() {
  myClient = new myClient();
  $(window).resize(function() {
      console.log("window resized");
      myClient.viewResized();
    });
});

How do I get the svgCanvasHeight in drawSvg dynamically so that when the window is resized, so does the svg's viewBox and svg?

djdy
  • 6,779
  • 6
  • 38
  • 62
khinester
  • 3,398
  • 9
  • 45
  • 88

1 Answers1

0

Answered here: Get the real size of a SVG/G element

With regards to viewBox:

I have had a lot of problems with SVG and jQuery.

While html attributes are case-insensitive the svg ones (like viewBox) aren't. I'd try using the element.setAttribute(name, value) native JS function. This worked for me, and make sure you're using viewBox with the capital B.

Community
  • 1
  • 1
ChrisIPowell
  • 494
  • 2
  • 6