【问题标题】:CSS Border Transition On Page Load?页面加载时的 CSS 边框过渡?
【发布时间】:2020-07-08 07:13:17
【问题描述】:

我想在我的页面加载后制作一个定时边框绘制动画。我基本上希望隐藏 div 容器的边框,然后通过转换来绘制容器边框,由正在加载的页面触发(不悬停)。我能够在悬停时找到如何执行此操作,但我无法弄清楚如何在页面加载时执行此操作。我将如何在下面的代码中实现它?

<div id="profile-content">
     Insert Content Here
 </div>

 #profile-content
 {
     border: 3px solid;
     border-color: #FFFFFF;
     padding: 4em 4em 4em 14em;
     margin: 0 0 0 4em;
 }

【问题讨论】:

  • 您可以开始,正确解释您希望“定时边框绘制动画” 的实际外观。然后你会告诉我们你的研究到目前为止已经出现了什么,以及你自己的尝试产生了什么结果。请阅读How to Ask。
  • 刚刚编辑过。对于措辞含糊的问题,我深表歉意。 @CBroe

标签: html css animation transition


【解决方案1】:

查看边框过渡的方法有很多,我只展示了一对。

Source

有一个属性transition,它接受seconds作为参数来给你效果。

#profile-content {
  outline: solid 5px #FC5185;
  transition: outline 0.6s linear;
  margin: 0.5em;
}

#profile-content:hover {
  outline-width: 10px;
}
<div id="profile-content">
  Insert Content Here
</div>

或

Div边框过渡:

div {
  background: none;
  border: 0;
  box-sizing: border-box;
  margin: 1em;
  padding: 1em 2em;
  box-shadow: inset 0 0 0 2px #f45e61;
  color: #f45e61;
  font-size: inherit;
  font-weight: 700;
  position: relative;
  vertical-align: middle;
  width: auto;
}

div::before,
div::after {
  box-sizing: inherit;
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
}

#profile-content {
  -webkit-transition: color 0.25s;
  transition: color 0.25s;
}

#profile-content::before,
#profile-content::after {
  border: 2px solid transparent;
  width: 0;
  height: 0;
}

#profile-content::before {
  top: 0;
  left: 0;
}

#profile-content::after {
  bottom: 0;
  right: 0;
}

#profile-content:hover {
  color: Teal;
}

#profile-content:hover::before,
#profile-content:hover::after {
  width: 100%;
  height: 100%;
}

#profile-content:hover::before {
  border-top-color: black;
  border-right-color: black;
  -webkit-transition: width 1s ease-out, height 0.25s ease-out 0.25s;
  transition: width 0.25s ease-out, height 0.25s ease-out 0.25s;
}

#profile-content:hover::after {
  border-bottom-color: black;
  border-left-color: black;
  -webkit-transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
  transition: border-color 0s ease-out 0.5s, width 0.25s ease-out 0.5s, height 0.25s ease-out 0.75s;
}
<div id="profile-content">
  Insert Content Here
</div>

【讨论】:

  • 所以我希望能够在不悬停的情况下进行第二次转换。在加载页面一段时间后绘制 div 容器的边框。抱歉,这个问题措辞含糊。 @manjuboyz
  • 恐怕你没有太多选择,你需要创建一个js或jq函数来完成这项工作!因为在我们的例子中,一个事件应该恰好有一个过渡,它是悬停。
  • 在这里找到了一个可能对您有帮助的答案:stackoverflow.com/questions/6805482/…
  • 希望上面的网址可以帮到你!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-08
  • 2011-09-17
  • 2015-06-05
  • 1970-01-01
  • 1970-01-01
  • 2022-09-28
  • 2019-09-01
相关资源
最近更新 更多