HTML/CSS如何临时突出显示页面的一部分[重复]

kulphzqa  于 2023-05-02  发布在  其他
关注(0)|答案(4)|浏览(126)

此问题已在此处有答案

Yellow fade effect with JQuery(15个回答)
6年前关闭。
例如,如果您转到此链接,它会暂时 Flink 答案。
这是如何实施的?
这是一些bootstrap/css的东西吗?
我试着用谷歌搜索,但我不知道这个 Flink 的高亮功能叫什么。

p8ekf7hl

p8ekf7hl1#

您可以使用css animation来实现,请尝试以下操作:

div{
  width:100%;
  height:auto;
  animation:bg 2s ease-in;
  -webkit-animation:bg 2s ease-in;
  -moz-animation:bg 2s ease-in;
  -ms-animation:bg 2s ease-in;
  -o-animation:bg 2s ease-in;
}

@-webkit-keyframes bg{
  0%{
    background:rgba(255,165,0,1);
  }  
  20%{
        background:rgba(255,165,0,0.8);
  }
  50% 70%{
        background:rgba(255,165,0,0.5);
  }
  100%{
    background:rgba(255,165,0,0);
  }
}

@-moz-keyframes bg{
  0%{
    background:rgba(255,165,0,1);
  }  
  20%{
        background:rgba(255,165,0,0.8);
  }
  50% 70%{
        background:rgba(255,165,0,0.5);
  }
  100%{
    background:rgba(255,165,0,0);
  }
}

@-ms-keyframes bg{
  0%{
    background:rgba(255,165,0,1);
  }  
  20%{
        background:rgba(255,165,0,0.8);
  }
  50% 70%{
        background:rgba(255,165,0,0.5);
  }
  100%{
    background:rgba(255,165,0,0);
  }
}

@-o-keyframes bg{
  0%{
    background:rgba(255,165,0,1);
  }  
  20%{
        background:rgba(255,165,0,0.8);
  }
  50% 70%{
        background:rgba(255,165,0,0.5);
  }
  100%{
    background:rgba(255,165,0,0);
  }
}
<div>
<p>
Dummy Content Dummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy ContentDummy Content
</p>
</div>
mkshixfv

mkshixfv2#

这可以用JavaScript实现。

var bgopacity = 1.0;

var bgfade = function() {
  var comment = document.getElementById("comment");
  bgopacity -= 0.02;
  comment.style.backgroundColor = "rgba(255, 242, 130, " + bgopacity + ")";
  if (bgopacity >= 0) {
    setTimeout(bgfade, 30);
  }
}

bgfade();

https://jsfiddle.net/Lpo92shj/

cgvd09ve

cgvd09ve3#

这被称为黄色褪色技术,已经有一个关于SO的问题:Yellow fade effect with JQuery和这里也有一些关于这个的更多信息:https://signalvnoise.com/archives/000558.php要跳转到一个部分并突出显示它,您可以用途:target这里有更多信息:https://css-tricks.com/on-target/

rta7y2nd

rta7y2nd4#

这可以通过css3动画来实现。.
请在此处查看演示

var answer=document.createElement('div');
answer.innerHTML='<div id="answer">\
 <h1>\
  My answer\
 </h1>\
</div>'
setTimeout(function(){document.body.appendChild(answer)},3000)
@keyframes animate {
  from {
    background: transparent
  }
  50% {
    background: #f2e68e;
  }
  100% {
    background: transparent;
  }
}

@-webkit-keyframes animate {
  from {
    background: transparent;
  }
  50% {
    background: #f2e68e;
  }
  100% {
    background: transparent;
  }
}
@-o-keyframes animate {
  from {
    background: transparent;
  }
  50% {
    background: #f2e68e;
  }
  100% {
    background: transparent;
  }
}

#answer {
  animation-name: animate;
  animation-duration: 3s;
  animation-iteration-count: 1;
  -moz-animation-name: animate;
  -moz-animation-duration: 3s;
  -moz-animation-iteration-count: 1;
  -o-animation-name: animate;
  -o-animation-duration: 3s;
  -o-animation-iteration-count: 1;  
  -webkit-animation-name: animate;
  -webkit-animation-duration: 3s;
  -webkit-animation-iteration-count: 1;
}
<div>
Please wait I will inject this answer and hightlight it</div>

相关问题