简体   繁体   English

动画会创建可移动页面内容的div吗?

[英]Animation creates a div that moves my page content?

I have the following site on which I tried implementing a very nice looking animation. 我在以下网站上尝试实现了非常漂亮的动画。 I don't know why but it keeps creating white space around my page and if I also add a button (as I did in the fiddle) it just goes crazy. 我不知道为什么,但是它一直在页面周围创建空白,如果我还添加一个按钮(就像我在小提琴中所做的那样),那就太疯狂了。 What is the solution to this? 有什么解决方案?

FIDDLE: https://jsfiddle.net/7suL84my/ 内容: https ://jsfiddle.net/7suL84my/

CODE OF ANIMATION: 动画代码:

// Some random colors
const colors = ["#3CC157", "#2AA7FF", "#1B1B1B", "#FCBC0F", "#F85F36"];

const numBalls = 50;
const balls = [];

for (let i = 0; i < numBalls; i++) {
let ball = document.createElement("div");
ball.classList.add("ball");
ball.style.background = colors[Math.floor(Math.random() * colors.length)];
ball.style.left = `${Math.floor(Math.random() * 100)}vw`;
ball.style.top = `${Math.floor(Math.random() * 100)}vh`;
ball.style.transform = `scale(${Math.random()})`;
ball.style.width = `${Math.random()}em`;
ball.style.height = ball.style.width;

balls.push(ball);
document.body.append(ball);
}

// Keyframes
balls.forEach((el, i, ra) => {
let to = {
x: Math.random() * (i % 2 === 0 ? -11 : 11),
y: Math.random() * 12
};

let anim = el.animate(
 [
  { transform: "translate(0, 0)" },
  { transform: `translate(${to.x}rem, ${to.y}rem)` }
],
{
  duration: (Math.random() + 1) * 2000, // random duration
  direction: "alternate",
  fill: "both",
  iterations: Infinity,
  easing: "ease-in-out"
}
);
});

From your link on the css file change this : 从css文件上的链接更改此:

#main{
background-color:black;
color:white;
width:98%;
height:98%;
align-content: center;

}

to this: 对此:

#main{
background-color:black;
color:white;
width:100%;
height:100%;
align-content: center;

}

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

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