2013-01-07 5 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(); 
    }); 
}); 

가 어떻게 drawSvg에 svgCanvasHeight을받을 수 있나요을 동적으로 SVG의 뷰 박스와 SVG 창 크기를 조정할 때, 그렇게 너무?

답변

0

여기 답변 : 안부 Get the real size of a SVG/G element

뷰 박스에 :

나는 SVG와 jQuery로 많은 문제가 있었다.

html 속성은 대소 문자를 구분하지 않지만 viewBox와 같은 svg 속성은 대소 문자를 구분하지 않습니다. element.setAttribute (name, value) 네이티브 JS 함수를 사용해 보겠습니다. 이것은 나를 위해 일했고, 당신이 수도 B와 viewBox를 사용하고 있는지 확인하십시오.