背景转换完成后要淡入的文本

text to fade in after background transition completed

本文关键字:淡入 文本 转换 背景      更新时间:2023-12-16

我的背景有带过渡的图像。背景转换完成后,文本必须淡入。我使用了转换延迟,但它在mozilla中有效,而在chrome中无效。至于渐变效果,它在铬中有效,而在mozzilla中无效。现在,我只想让文本在延迟后淡出。请如何更正我的代码以实现这一点?

css

.text2
{
    margin-top:10%;
    margin-left:0;
    padding-left:0;

    /*fade in effect*/
     transition-delay: 2s;
    -moz-transition-delay:2s;
    -o-transition-delay:2s;
    -webkit-transition-delay:2s;
     animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
    -o-animation: fadein 2s; /* Opera */
}
@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-moz-keyframes fadein { /* Firefox */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-o-keyframes fadein { /* Opera */
    from {
        opacity:0;
    }
    to {
        opacity: 1;
    }
}
#target {
    position: relative;
    left:0;
    background-image:url('../img/top-bg.jpg');background-repeat:no-repeat;
     width: 120%;
    background-size:cover;
     height: 600px;  
    background-position: 200px 50%;
  transition: background-position 2s ease-in-out;
}

#target.wide{
    left: -20%;
    padding-left: 30%;
   background-position: 0px 50%;
}

脚本

<script>
  $(document).ready(function () {
        $('#target').toggleClass("wide");
});
  </script>

html

    <div id="target">
        <div class="small-12 medium-11 large-11 columns text2">
                 Beyond Law,<br/>
                 The Spirit of Innovation is Our strenght.
                 </div>
    </div>

</div>
<div style="clear: both"></div>

链接:

http://vani.valse.com.my/beldon/index.php

编辑

text2
{
    margin-top:10%;
    margin-left:0;
    padding-left:0;

    /*fade in effect*/
    **transition: opacity 0.5s ease-in;**
     animation: fadein 2s;
    -moz-animation: fadein 2s; /* Firefox */
    -webkit-animation: fadein 2s; /* Safari and Chrome */
    -o-animation: fadein 2s; /* Opera */
   transition-delay: 2s;
    -moz-transition-delay:2s;
    -o-transition-delay:2s;
    -webkit-transition-delay:2s;
}

添加了粗体行。它在mozilla中按需工作,但在chrome中转换延迟不起作用。

我在动画后添加了下面的行,如下所示,并使其在chrome中工作。

-webkit-animation-delay: 4s; /* Chrome, Safari, Opera */
  /*to make the text not visible untill the transition starts*/
   -webkit-opacity: 0;
   /*without this the text will disappear after the animation*/
    -webkit-animation-fill-mode: forwards;

所以在完整的中应该是这样的

.text2
{
    margin-top:10%;
    margin-left:0;
    padding-left:0;

    /*fade in effect*/
     transition: opacity 0.5s ease-in;
    -webkit-transition: opacity 0.5s ease-in;
    -moz-transition: opacity 0.5s ease-in;
    -o-transition: opacity 0.5s ease-in;
     animation: fadein 4s;
    -moz-animation: fadein 4s; /* Firefox */
   -webkit-animation: fadein 4s; /* Safari and Chrome */
    -o-animation: fadein 4s; /* Opera */
     transition-delay: 4s;
    -moz-transition-delay:4s;
    -o-transition-delay:4s;
    -webkit-transition-delay:4s;
   -webkit-animation-delay: 4s; /* Chrome, Safari, Opera */
  /*to make the text not visible untill the transition starts*/
   -webkit-opacity: 0;
   /*without this the text will disappear after the animation*/
    -webkit-animation-fill-mode: forwards;
}
@keyframes fadein {
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-moz-keyframes fadein { /* Firefox */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-webkit-keyframes fadein { /* Safari and Chrome */
    from {
        opacity:0;
    }
    to {
        opacity:1;
    }
}
@-o-keyframes fadein { /* Opera */
    from {
        opacity:0;
    }
    to {
        opacity: 1;
    }
}