Проблема с изображением SVG, попытка создать анимацию, но штрих-дашаррей не работает - PullRequest
0 голосов
/ 28 мая 2020

У меня проблема с моим изображением SVG. Я хочу создать анимацию. Когда я использую stroke-dasharray в CSS, мое изображение не меняется. Вот мой код. Мне нужна помощь.


<svg 
                id="logo"
                width="39" height="43" viewBox="0 0 39 43" fill="none" xmlns="http://www.w3.org/2000/svg">
                <g filter="url(#filter0_d)">
                <path d="M26.8047 26.0938H12.5078L9.29688 35H4.65625L17.6875 0.875H21.625L34.6797 35H30.0625L26.8047 26.0938ZM13.8672 22.3906H25.4688L19.6562 6.42969L13.8672 22.3906Z" fill="white"/>
                </g>
                <defs>
                <filter id="filter0_d" x="0.65625" y="0.875" width="38.0234" height="42.125" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
                <feFlood flood-opacity="0" result="BackgroundImageFix"/>
                <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0"/>
                <feOffset dy="4"/>
                <feGaussianBlur stdDeviation="2"/>
                <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0"/>
                <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow"/>
                <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape"/>
                </filter>
                </defs>
                </svg>

Вот мой CSS код:


body {
  font-family: 'Nunito', sans-serif;
  width: 100%;
  height: 100vh;
}

#logo{
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#logo path:nth-child(1){
    stroke-dasharray: 200px;
    stroke-dasharray: 50px;
}

1 Ответ

2 голосов
/ 28 мая 2020

Я не очень уверен, что вы спрашиваете об этом. Вот что я комментировал:

Вне отфильтрованной группы я добавляю элемент использования: <use xlink:href="#a" id="theUse" />. В css я использую стили, которые вы даете #logo path:nth-child(1)

body {
  font-family: 'Nunito', sans-serif;
  width: 100%;
  height: 100vh;
}

#logo{
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%);
}

#theUse{
    stroke:silver;
    /*stroke-dasharray: 200px;*/
    stroke-dasharray: 50px;
}
<svg id="logo" width="200" viewBox="0 0 39 43" fill="none" xmlns="http://www.w3.org/2000/svg">
  <g filter="url(#filter0_d)">
    <path id="a" d="M26.8047 26.0938H12.5078L9.29688 35H4.65625L17.6875 0.875H21.625L34.6797 35H30.0625L26.8047 26.0938ZM13.8672 22.3906H25.4688L19.6562 6.42969L13.8672 22.3906Z" fill="white" />

  </g>
<use xlink:href="#a" id="theUse" />
  <defs>
    <filter id="filter0_d" x="0.65625" y="0.875" width="38.0234" height="42.125" filterUnits="userSpaceOnUse" color-interpolation-filters="sRGB">
      <feFlood flood-opacity="0" result="BackgroundImageFix" />
      <feColorMatrix in="SourceAlpha" type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0" />
      <feOffset dy="4" />
      <feGaussianBlur stdDeviation="2" />
      <feColorMatrix type="matrix" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.25 0" />
      <feBlend mode="normal" in2="BackgroundImageFix" result="effect1_dropShadow" />
      <feBlend mode="normal" in="SourceGraphic" in2="effect1_dropShadow" result="shape" />
    </filter>
  </defs>
</svg>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...