javascript – CSS动画宽度从右到左,高度从下到上

我试图解决从右到左扩展div的宽度和从下到上的不同容器的高度的问题.我正在尝试创建将在正方形旋转的CSS动画,并且模仿这里的边框是我的CodePen https://codepen.io/Archezi/pen/xReqvq?editors=0100链接,如果有帮助的话.

这是我的HTML .container是一个主要包装.circle是一个动画line1-line4是正方形的边框,我正在尝试动画.

<div class="container">
    <div class="circle "></div>
    <div class="line1  "></div>
    <div class="line2  "></div>
    <div class="line3  "></div>
    <div class="line4  "></div>
</div>

这是我的CSS

body {
    margin: 0 auto;
}
.container {
    position:relative;
    margin: 50px auto;
    width: 800px;
    height:800px;
    border:1px solid #000;
}
.circle {
    display:inline-block;
    width: 25px;
    height: 25px;
    border-radius:50%;
    position: absolute;
    top:100px;
    left:100px;
    background:#000;
    animation: myframes 4s ease-in-out 0s infinite;

    /* animation-name: myanimation;
    animation-duration:5s;
    animation-timing-function:ease-in-out;
    animation-delay: 0s;
    animaiton-iteration-count: infinite;
    animation-direction: normal;
    animation-fill-mode: forwards;
    animation-play-state: running; */
}
.line1 {
    height:15px;
    width:15px;
    position:absolute;
    top:105px;
    left:105px;
    background:red;
    animation: squerframe 2s ease-in-out 0s infinite;
}
.line2 {
    height:15px;
    width:15px;
    position:absolute;
    top:105px;
    left:205px;
    background:green;
    animation: squerframe2 2s ease-in-out 1s infinite;
}
.line3 {
    height:15px;
    width:15px;
    position:absolute;
    top:205px;
    left:205px;
    background-color:red;
    animation: squerframe3 2s ease-in-out 2s infinite;
}

.line4 {
    height:15px;
    width:15px;
    position:absolute;
    top:205px;
    left:105px;
    background:green;
    animation: squerframe4 2s ease-in-out 3s infinite;
}
@Keyframes squerframe 
{
    0%  {  width:15px; opacity: 1; }
    50% {  width:115px; }
    100%{  width:115px; opacity: 0; }
}
@Keyframes squerframe2 
{
    0%  { height:15px;  opacity: 1; }
    50% { height:115px;             }
    100%{ height:115px;  opacity: 0;  }
}
@Keyframes squerframe3 
{
    0%  { width:115px; opacity: 0;}
    50% { width:115px; }
    100%{ width:15px; opacity: 1; }
}
@Keyframes squerframe3 
{
    0%  { width:15px; opacity: 1;}
    50% { width:115px;  }
    100%{ width:115px; opacity: 0; }
}
@Keyframes squerframe4 
{
    0%  {  height:15px; opacity: 1;}
    50% {  height:115px;  }
    100%{  height:115px; opacity: 0; }
}

@keyframes myframes 
{
    0%   { top:100px; left:100px; }
    25%  { top:100px; left:200px; }
    50%  { top:200px; left:200px; }  
    75%  { top:200px; left:100px; }
    100% { top:100px; left:100px; }
}

请指导我在哪里找到解决方案或指出我对这个问题的不同方法.谢谢!

解决方法

这里的问题是你需要line3具有绝对权限,这样当宽度改变时,它将向左伸展.

另外,第4行应该有一个绝对的底部,所以它会伸展.

我建议您添加一个容器或更改当前div.container的维度(就像我在示例中所做的那样)为四行,并使用4行作为该容器的极值.

以下是您修改的示例,作为如何继续的参考点:

https://codepen.io/anon/pen/MbRvGM?editors=0100

body {
  margin: 0 auto;
}
.container {
  position:relative;
  margin: 50px auto;
  width: 115px;
  height:115px;
  border:1px solid #000;
}
.circle {
  display:inline-block;
  width: 25px;
  height: 25px;
  border-radius:50%;
  position: absolute;
  top:0px;
  left:0px;
  background:#000;
  animation: myframes 4s ease-in-out 0s infinite;

/*   animation-name: myanimation;
  animation-duration:5s;
  animation-timing-function:ease-in-out;
  animation-delay: 0s;
  animaiton-iteration-count: infinite;
  animation-direction: normal;
  animation-fill-mode: forwards;
  animation-play-state: running; */



}
.line1 {
  height:15px;
  width:15px;
  position:absolute;
  top:0px;
  left:0px;
  background:red;
  animation: squerframe 2s ease-in-out 0s infinite;
}
.line2 {
  height:15px;
  width:15px;
  position:absolute;
  top:0px;
  left:100px;
  background:green;
  animation: squerframe2 2s ease-in-out 1s infinite;
}
.line3 {
  height:15px;
  width:15px;
  position:absolute;
  top:100px;
  right:0px;
  float: right;
  background-color:red;
  animation: squerframe3 2s ease-in-out 2s infinite;
}

.line4 {
  height:15px;
  width:15px;
  position:absolute;  
  left:0px;
  bottom: 0;
  background:green;
  animation: squerframe4 2s ease-in-out 3s infinite;
}
@Keyframes squerframe 
{
  0%  {  width:15px; opacity: 1; }
  50% {  width:115px; }
  100%{  width:115px; opacity: 0; }
}
@Keyframes squerframe2 
{
  0%  { height:15px;  opacity: 1; }
  50% { height:115px;             }
  100%{ height:115px;  opacity: 0;  }
}
@Keyframes squerframe3 
{
  0%  { width:115px; opacity: 0;}
  50% { width:115px; }
  100%{ width:15px; opacity: 1; }
 }
@Keyframes squerframe3 
{
  0%  { width:15px; opacity: 1;}
  50% { width:115px;  }
  100%{ width:115px; opacity: 0; }
}
@Keyframes squerframe4 
{
  0%  {  height:15px; opacity: 1;}
  50% {  height:115px;  }
  100%{  height:115px; opacity: 0; }
}

 @keyframes myframes 
{
   0%   { top:0px; left:0px; }
   25%  { top:0px; left:100px; }
   50%  { top:100px; left:100px; }  
   75%  { top:100px; left:0px; }
   100% { top:0px; left:0px; }
}

相关文章

事件冒泡和事件捕获 起因:今天在封装一个bind函数的时候,发现el.addEventListener函数支持第三个参数...
js小数运算会出现精度问题 js number类型 JS 数字类型只有number类型,number类型相当于其他强类型语言...
什么是跨域 跨域 : 广义的跨域包含一下内容 : 1.资源跳转(链接跳转,重定向跳转,表单提交) 2.资源...
@ &quot;TOC&quot; 常见对base64的认知(不完全正确) 首先对base64常见的认知,也是须知的必须有...
搞懂:MVVM模式和Vue中的MVVM模式 MVVM MVVM : 的缩写,说都能直接说出来 :模型, :视图, :视图模...
首先我们需要一个html代码的框架如下: 我们的目的是实现ul中的内容进行横向的一点一点滚动。ul中的内容...