SVG ViewBox未加载

问题描述

我已经在wordpress主题中实现了一个SVG脚本来加载特定形状,svg可以很好地加载,但是viewBox根本没有加载,这使得形状看起来令人毛骨悚然。

$svg是要加载的附件ID。

<script>
    var <?PHP echo $e ?> = Snap("#categories > .categories-container .<?PHP echo $cat ?>");
    var <?PHP echo $cont ?> = jQuery(".<?PHP echo $cat ?>").get(0);
    var <?PHP echo $width ?> = jQuery(".<?PHP echo $cat ?>").width();
    var <?PHP echo $height ?> = (<?PHP echo $width ?>) / 3;
    <?PHP
    if($i==1 || $i==2)
    {
        $svg = 456;
    }
    else
    {
        $svg = 456;
    }
    ?>
    var maxHeight = 0;
    
    Snap.load("<?PHP echo wp_get_attachment_url( $svg ) ?>",function(<?PHP echo 'svg' . ($i+1) ?>) {
        <?PHP echo $e ?>.append(<?PHP echo 'svg' . ($i+1) ?>);
        <?PHP
            if($i==1 || $i==2)
            {
               echo "var startpoints = [0,100,100];";
               echo "var endpoints = [0,50,100];";

        ?>
        <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg").attr({viewBox:[0,100].join(',')});
        <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg").attr({viewBox:[0,100].join(' ')});
        <?PHP
            }
            else
            {
                echo "var startpoints = [0,150,100];";
                echo "var endpoints = [0,100];";
            }
        ?>

        <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg > g > g").polygon({
            points: startpoints,fill: 'url(#linear-gradient)',fillOpacity: 0.9
        });

        if (<?PHP echo $i ?> === 0)
            <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg > g > g > g > image").attr("class","maxHeight");

        <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg > g > g > g > image").attr({
            width: 150,height: 100
        });

        var maxHeight = 0;
        if (<?PHP echo $i ?> === 1){
            maxHeight = jQuery(".category1").height();
            jQuery(".introduction").height( maxHeight - 5 );
        }
        else if (<?PHP echo $i ?> === 2)
            maxHeight = jQuery(".category2").height() * 2 + 12;

        if (<?PHP echo $i ?> === 1 || <?PHP echo $i ?> === 2) {

            <?PHP echo $e ?>.select(".<?PHP echo $cat ?> > svg").attr({
                preserveAspectRatio: "none",width: "100%",height: maxHeight / 2 - 6,background: 'url(im)',backgroundRepeat: 'no-repeat',backgroundSize: "cover",backgroundPosition: "center",});

        }

        <?PHP echo $cont ?>.addEventListener("mouseenter",function(event) {
            <?PHP echo $e ?>.select(".<?PHP echo $cat ?> polygon").stop().animate({
                points: endpoints
            },500,mina.easein);
        });
        <?PHP echo $cont ?>.addEventListener("mouseleave",function(event) {
            <?PHP echo $e ?>.select(".<?PHP echo $cat ?> polygon").stop().animate({
                points: startpoints
            },mina.easein);
        });
    });

</script>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)