简体   繁体   English

动画在窗口调整大小上的位置

[英]Animation positioning on window resize

I was wondering if it was possible to use jquery window.resize() to ensure the two donuts positioning never collides with the home text in the middle. 我想知道是否有可能使用jquery window.resize()来确保两个甜甜圈的位置永远不会与中间的主文本冲突。 I'm not sure how to link the x and y of the window size to change the top/left and bottom/right positioning values. 我不确定如何链接窗口大小的x和y来更改顶部/左侧和底部/右侧的定位值。

Or is there a way I could decrease the width and height of the donuts on window resize? 还是有办法减少窗口调整大小时甜甜圈的宽度和高度?

Any help would be appreciated! 任何帮助,将不胜感激!

 html, body { margin: 0; } #container { width: 100vw; height: 100vh; background-color: pink; display: flex; align-items: center; overflow: hidden; position: relative; } #donut img, #donut2 img { width: 500px; height: 500px; } #donut { width: auto; height: auto; position: absolute; animation: donut 2s; animation-fill-mode: forwards; } @keyframes donut { 0% { left: -20%; top: -20%; transform: translateZ(-100px); } 100% { left: -5%; top: -5%; transform: translateZ(100px); } } #donut2 { width: auto; height: auto; position: absolute; animation: donut2 2s; animation-fill-mode: forwards; } @keyframes donut2 { 0% { right: -20%; bottom: -20%; transform: translateZ(-100px); } 100% { right: -5%; bottom: -5%; transform: translateZ(-100px); } } #homeText { width: 100%; height: auto; text-align: center; font-size: 30px; } 
 <div id="container"> <div id="donut"> <img src="https://upload.wikimedia.org/wikipedia/commons/a/a5/Glazed-Donut.jpg"> </div> <div id="homeText"> <p> Reward Points </p> <p>Get Your Daily Sweet Rewards</p> </div> <div id="donut2"> <img src="https://upload.wikimedia.org/wikipedia/commons/a/a5/Glazed-Donut.jpg"> </div> </div> 

Please Try This. 请尝试一下。 I think this should be work:- 我认为这应该可行:

#container {
  width: 100vw;
  height: 100vh;
  background-color: pink;
  display: flex;
  align-items: center;
  -webkit-justify-content: center;
  justify-content: center;
}

#donut { width:30vw; }
#donut2 { width:30vw; }
#donut2 img, #donut img {
  width: 100%;
  max-width:100%;
  height:auto;
}

#donut {
  position: absolute;
  animation: donut 2s;
  animation-fill-mode: forwards;
}

@keyframes donut {
  0% {
    left: -5%;
    top: -5%;
    transform: translateZ(-100px);
  }
  100% {
    left: 5%;
    top: 5%;
    transform: translateZ(100px);
  }
}

#donut2 {
  position: absolute;
  animation: donut2 2s;
  animation-fill-mode: forwards;
}

@keyframes donut2 {
  0% {
    right: -5%;
    bottom: -5%;
    transform: translateZ(-100px);
  }
  100% {
    right: 5%;
    bottom: 5%;
    transform: translateZ(-100px);
  }
}

#homeText {
  width: 25vw;
  height: auto;
  text-align: center;
  font-size: 30px;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM