इसके लिए मैंने जो समाधान पाया वह .getComputedStyle()
का उपयोग करना था। और चूंकि svg
तत्व पुराने IE8- ब्राउज़र में समर्थित नहीं हैं, .getComputedStyle()
लगातार परिणाम देने का तरीका है।
var heightComponents = ['height', 'paddingTop', 'paddingBottom', 'borderTopWidth', 'borderBottomWidth'],
widthComponents = ['width', 'paddingLeft', 'paddingRight', 'borderLeftWidth', 'borderRightWidth'];
var svgCalculateSize = function (el) {
var gCS = window.getComputedStyle(el), // using gCS because IE8- has no support for svg anyway
bounds = {
width: 0,
height: 0
};
heightComponents.forEach(function (css) {
bounds.height += parseFloat(gCS[css]);
});
widthComponents.forEach(function (css) {
bounds.width += parseFloat(gCS[css]);
});
return bounds;
};
यह एक ज्ञात बग तो है:
तो मैं अपने पुस्तकालय में इस समारोह का उपयोग कर समाप्त हो गया? – Gajus