如何单独更改SVG图像的宽度/高度,以更改宽高比?我希望这样做的SVG是<img>
元素。如何拉伸SVG图像?
1
A
回答
0
感谢@DeepthiS我决定创建自己的解决这个问题,我创建了以下代码(我也将在GitHub上提供)将具有自定义属性的所有<img>
元素转换为内联<svg>
具有属性preserveAspectRatio="none"
的元素
$('[magnitude]').each(function(){
var el=this;
$.get(el.src, function(doc){
var svg = $(doc).find("svg").attr(inheritedAttributes());
$(svg).attr(inheritedAttributes(el))
console.log(inheritedAttributes(el))
$(el).replaceWith(svg);
}, "xml");
});
function inheritedAttributes(el){
ob = new Object();
//Inherited Attributes
ob.id = $(el).attr("id");
ob.source = $(el).attr("src");
ob.magnitude = $(el).attr("magnitude");
ob.width = $(el).attr("width");
ob.height = $(el).attr("height");
//Special Attributes for Magnitude functionality
ob.preserveAspectRatio = "none"
return ob
};
(请注意:由于使用AJAX,Chrome无法运行。我很乐意提供任何解决此问题的建议。)
2
SVG文件应有preserveAspectRatio设置为“无”
您可以参考此Plunker:。http://plnkr.co/edit/9FmjYPetNOrRT1aPTewn?p=preview
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="612px" height="502.174px" viewBox="0 65.326 612 502.174" enable-background="new 0 65.326 612 502.174"
xml:space="preserve" preserveAspectRatio="none">
</svg>
+0
有没有办法在不改变SVG文件本身的情况下做同样的事情?我希望能够使用Illustrator中的文件完成此操作。 –
相关问题
- 1. SVG:伸展图像
- 2. Supersized - 如何拉伸图像?
- 3. 如何拉伸图像
- 4. 拉伸图像
- 5. 拉伸图像
- 6. ResponsiveSlides.js拉伸图像
- 7. 拉伸图像CSS?
- 8. 图像被拉伸
- 9. 图像被拉伸
- 10. 如何根据右侧拉伸图像?
- 11. 如何在Matlab中拉伸图像
- 12. 如何用CSS拉伸图像?
- 13. 如何在Firemonkey中拉伸图像?
- 14. 如何保存拉伸的图像?
- 15. 如何在ImageView中拉伸图像?
- 16. 你如何拉伸背景图像
- 17. SVG标志拉伸问题
- 18. 拉伸并旋转SVG图像的特定部分
- 19. 拉伸iOS背景图像
- 20. 图像拉伸并居中?
- 21. Overwide网页,图像拉伸?
- 22. 图像拉伸在ios
- 23. UISegmentedControl中的拉伸图像
- 24. UINavBar拉伸图像边缘
- 25. 图像不拉伸imageView android
- 26. 按钮图像拉伸
- 27. 拉伸图像高度css
- 28. iPhone:拉伸梯度图像
- 29. 背景图像拉伸
- 30. 在Java中拉伸图像
或设置类并向其添加样式(以%或px表示)。 –