圈动画
这是我试图创建的圈子越来越多的动画。
的什么happends短explination:
- 需要一个容器元件(相对定位)。
- 点击元素(绝对位置)。
- 在元素上添加单击事件侦听器。
- 单击事件创建一个同级元素(绝对定位)。
- 将此元素定位在点击元素的中心。
- 增加圆圈的大小。
/*document.addEventListener('"DOMContentLoaded', function() {*/
var spesial = document.getElementsByClassName("spesial");
var container = document.getElementsByClassName("container");
var togglecircle = false;
spesial[0].addEventListener('click', function() {
var circle = document.createElement('div');
circle.className = "circle"
container[0].appendChild(circle);
var size = 0;
if (this.offsetWidth > this.offsetHeight) {
size = container[0].offsetWidth;
} else {
size = container[0].offsetHeight;
}
console.log(this.offsetTop);
circle.style.top = this.offsetTop + (this.offsetHeight/2) + "px";
circle.style.left = this.offsetLeft + (this.offsetWidth/2) + "px";
circle.style.width = size * 2 + "px";
circle.style.height = size * 2 + "px";
});
/*});*/
.container {
position: relative;
height: 300px;
background-color: black;
overflow: hidden;
}
.spesial {
z-index: 10;
position: absolute;
top: 50px;
left: 50px;
width: 50%;
height: 150px;
background-color: yellow;
border: 2px solid #888;
cursor: pointer;
}
.circle {
position: absolute;
z-index: 1;
border-radius: 50%;
width: 0px;
height: 0px;
transition: width 3s, height 3s;
background-color: yellow;
transform: translate(-50%, -50%);
}
<div class="container">
<div class="spesial">
<h1>Cool header</h1>
<p>lorem ipsum etc, etc,</p>
</div>
</div>
这工作,相当不错。但是当这个容器需要降低屏幕时会发生什么?假设上面有一个导航条和标题图像,那么容器div在那之后开始。从“overflow:hidden”这个圆圈的高度不会被限制在容器的顶部吗? – tehfailsafe
只要容器很大,您就可以随时在身体中的圆圈。 (容器可以是身体) – Persijn