Javascript 在调整窗口大小时自动调整svg
我有以下代码:Javascript 在调整窗口大小时自动调整svg,javascript,jquery,jquery-svg,Javascript,Jquery,Jquery 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
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的viewBox和svg也会这样做?回答如下:
关于viewBox:
我在SVG和jQuery方面遇到了很多问题
html属性不区分大小写,而svg属性(如viewBox)则不区分大小写。我会尝试使用element.setAttribute(name,value)原生JS函数。这对我很有用,请确保您使用的是大写字母B的viewBox