jquery - 加载边框动画?

标签 jquery css

我想知道如何制作边框效果。我所做的只是 css3 中的淡入淡出效果:http://jsfiddle.net/ueu64hps/ ,但我仍然想要那种滑动效果。谢谢。

例如,http://velvethammer.net/边界从 20% 滑入 100%。 这正是我想要的,但在页面加载时。

我将在下面粘贴我的代码:

HTML:

<div id="left" class = "slow fade-in"></div>
  <div id="right" class = "slow fade-in"></div>
  <div id="top" class = "slow fade-in"></div>
  <div id="bottom" class = "slow fade-in"></div>


  <div class = "wrap">
    <h2>Some random text.</h2>     
  </div>

还有 CSS:

*{
  margin: 0;
  padding: 0;
}
#top, #bottom, #left, #right {
  background: black;
  position: fixed;
}
#left, #right {
  top: 0; bottom: 0;
  width: 35px;
}
#left { 
  left: 0; 
}
#right { 
  right: 0; 
}
#top, #bottom {
  left: 0; right: 0;
  height: 35px;
}
#top { 
  top: 0; 
}
#bottom { 
  bottom: 0; 
}
.wrap{
  margin:35px;
}
@-webkit-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@-moz-keyframes fadeIn { from { opacity:0; } to { opacity:1; } }
@keyframes fadeIn { from { opacity:0; } to { opacity:1; } }

.fade-in {
  opacity:0;  /* make things invisible upon start */
  -webkit-animation:fadeIn ease-in 1;  /* call our keyframe named fadeIn, use animattion ease-in and repeat it only 1 time */
  -moz-animation:fadeIn ease-in 1;
  animation:fadeIn ease-in 1;

  -webkit-animation-fill-mode:forwards;  /* this makes sure that after animation is done we remain at the last keyframe value (opacity: 1)*/
  -moz-animation-fill-mode:forwards;
  animation-fill-mode:forwards;

  -webkit-animation-duration:1s;
  -moz-animation-duration:1s;
  animation-duration:1s;
}
.fade-in.slow {
-webkit-animation-delay: 1.5s;
-moz-animation-delay: 1.5s;
animation-delay: 1.5s;
}

谢谢。

最佳答案

您可以同时为 #left、#right#top、#bottom 制作动画。这是 complete example .

创建 2 个动画集,一个用于宽度,另一个用于高度:

/* For left and right animation */
@-webkit-keyframes easeInLeft { from { width:0; } to { width:30px; } }
@-moz-keyframes    easeInLeft { from { width:0; } to { width:30px; } }
@keyframes         easeInLeft { from { width:0; } to { width:30px; } }

/* For top and bottom animation */    
@-webkit-keyframes easeInTop { from { height:0; } to { height:30px; } }
@-moz-keyframes    easeInTop { from { height:0; } to { height:30px; } }
@keyframes         easeInTop { from { height:0; } to { height:30px; } }

然后在各自的 div 上播放:

.ease-in-left {
    width: 0; /* Set it to 0 initially */
    -webkit-animation: easeInLeft ease-in 1;  
       -moz-animation: easeInLeft ease-in 1;
            animation: easeInLeft ease-in 1;
}

.ease-in-top {
    height: 0; /* Set it to 0 initially */
    -webkit-animation: easeInTop ease-in 1;  
       -moz-animation: easeInTop ease-in 1;
            animation: easeInTop ease-in 1;
}

下面是 div 的样子:

<div id="left" class = "slow fade-in ease-in-left"></div>
<div id="right" class = "slow fade-in ease-in-left"></div>
<div id="top" class = "slow fade-in ease-in-top"></div>
<div id="bottom" class = "slow fade-in ease-in-top"></div>

我保留了 .fade-in 类(您可能应该重命名它),使用通用的动画属性,并从它们所在的位置删除了 opacity 属性设置。

关于jquery - 加载边框动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26226126/

相关文章:

html - 在 div 的大小中包含填充

javascript - 无法使用 javascript 抓取和操作 HTML 元素

javascript - 让 jquery datepicker 每年在相同的日期使用不同的颜色

jquery - 如何将选择的插件添加到动态创建/克隆的 CSS div 中?

javascript - HTML Canvas 上奇怪的字体行为

html - 发送包含样式表的 HTML 电子邮件

html - 如何在悬停 CSS 上添加图像和更改可见性

javascript - 使用网格 ID 隐藏剑道网格工具栏

javascript - 如何使用复选框交换 DIVS

html - 星级在白色背景下不可见