【问题标题】:My first CSS animation with SVG works but not the second我的第一个带有 SVG 的 CSS 动画有效,但不是第二个
【发布时间】:2022-02-10 09:55:53
【问题描述】:

我无法多想,我尝试了很多变体,包括延迟、填充选项等……不可能(不幸的是,并非不可能)同一种东西比另一种不起作用。 我有一个由两个 SVG 组成的页面标题。我隐藏了两个 SVG,直到预加载器打开页面,然后用 Jquery 显示它们,然后第一个 SVG 出现并播放动画,然后过了一秒钟,另一个播放相同类型的动画。 Jquery 效果很好,第一个动画也播放得很好,但第二个没有。 我做了一个 jsfiddle,两个动画都运行良好:https://jsfiddle.net/igorlaszlo/r2gtwpmb/37/,所以我只是猜测插件/脚本可以阻止第二个动画。 这是我的测试网站:http://feketekutya.com/test/

HTML(我缩短了路径)

<section class="welcome">
    <svg xmlns="http://www.w3.org/2000/svg" width="1e3pt" height="350pt" viewBox="0 0 1e3 350" id="title">
        <path fill="none" stroke="#fff" class="go" d="..." />
    </svg>
    <svg xmlns="http://www.w3.org/2000/svg" width="400pt" height="70pt" viewBox="0 0 400 70" id="subtitle">
        <path fill="none" stroke="#2b4462" class="go2" d="..." />
</section>

CSS

#title {
  position:relative;
  display:none;
  margin:20% 0 0;
  padding:0 0 0 30px;
  width: 48%;
  max-width:1000px;
  height: auto;
  max-height:350px;
  filter: drop-shadow(1px 1px 0px rgba(0, 0, 0, 0.5));
  z-index:2
}
.go {
  stroke: #fff;
  stroke-dasharray: 1800;
  stroke-dashoffset: 1800;
  animation:go 3s linear forwards;
}
@keyframes go {
  0% {
      stroke-width: 4;
      stroke-dashoffset: 1800;
      fill: rgba(255,255,255,0);
  }
  100% {
    stroke-width: 1;
    stroke-dashoffset: 0;
    fill: rgba(255,255,255,1);
  }
}
#subtitle {
  position:relative;
  display:none;
  margin:50px 0 0;
  padding:0 0 0 32%;
  width: 20%;
  max-width:400px;
  height: auto;
  max-height:70px;
  z-index:2
}
.go2 {
  stroke: #2b4462;
  stroke-dasharray: 700;
  stroke-dashoffset: 700;
  animation:go2 3s linear forwards;
  fill: rgba(43,68,98,1);
}
@keyframes go2 {
  0% {
      stroke-width: 4;
      stroke-dashoffset: 700;
      fill: rgba(43,68,98,0);
  }
  100% {
    stroke-width: 1;
    stroke-dashoffset: 0;
    fill: rgba(43,68,98,1);
  }
}

jQuery

$(document).ready(function() {

    $('body').hide();
    
    //calling jPreLoader
    $('body').jpreLoader({
        showSplash: false,
        showPercentage: false,
        splashVPos: null,
        loaderVPos: null,
        autoClose: true,        
    }, function() { //callback function
        $('body').fadeIn(0);
        $('#title').css('display', 'block');
        $('#subtitle').css('display', 'block');
    });
}); 

【问题讨论】:

    标签: jquery svg css-animations


    【解决方案1】:

    我在您的网站上看不到字幕。请更改 CSS 中的填充。

    #subtitle {
     padding:0;
    ...
    ...
    }
    

    【讨论】:

    • 我无法将您的答案视为答案(但不是我否决了您的答案)。首先,当然你不能在我的网站上看到字幕,因为正如我所说:它只适用于 JSFiddle。其次,正如您在 JSFiddle 页面上看到的,即使没有零填充,它也能正常工作。
    • 最后你是对的,这太不可思议了......在 JSFiddle 中它与 padding:0 0 0 32% 一起工作,但在浏览器 (FF) 中却不行。现在,我已经更改了 padding: 0 和 margin: -50px 0 0 32%,它可以工作了。我仍然不明白为什么它在这里和那里的工作方式不同,但你有正确的答案......
    猜你喜欢
    • 1970-01-01
    • 2020-09-29
    • 2015-12-23
    • 2020-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多