gpt4 book ai didi

javascript - 覆盖 SVG 内联样式

转载 作者:行者123 更新时间:2023-11-28 16:34:02 26 4
gpt4 key购买 nike

 <svg id="mb-one_top" style="position: absolute; top: -215px;"  
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
preserveAspectRatio="xMidYMid" width="600" height="862" viewBox="0 0 600 862">

我试图让我的 SVG 在移动设备上更小,所以使用 jQuery 我写了:

var width = $(window).width();
if (width == 320) {
$('#mb-one_top').attr('width', '350');
}

但它并没有覆盖并使我的 SVG 宽度从 600 变为 350,知道吗?

最佳答案

我认为您可以使用这样的 CSS 代码轻松实现此目的

<style>
/* styles for mobile browsers smaller than 480px; (iPhone) */
@media (max-width:480px){
#mb-one_top {
width : 350px;
}
}
</style>

关于javascript - 覆盖 SVG 内联样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34861158/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com