2013-01-07 40 views
1

我有這樣的代碼:對自動配置功能窗口中的SVG調整

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(); 
    }); 
}); 

如何獲得svgCanvasHeight在drawSvg動態,這樣,當窗口大小,所以做了SVG的視框和SVG?

回答

0

在這裏找到答案:Get the real size of a SVG/G element

至於視框中:

我已經有很多與SVG和jQuery的問題。

雖然html屬性不區分大小寫,但svg的(如viewBox)不是。我會嘗試使用element.setAttribute(name,value)原生JS函數。這對我有效,並確保您使用viewBox與大寫B.