鼠标滑动到当前页面触发动画效果
Posted xiaoruaning
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了鼠标滑动到当前页面触发动画效果相关的知识,希望对你有一定的参考价值。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>浏览器滑动到当前界面触发动画</title>
<style>
* { margin:0; padding:0; }//reset css
.box { width:100%; height:1500px; background:gray; }
.two { width:100%; height:1500px; background:orange; }
.one { width:100%; height:1500px; background:pink; position:relative; }
.one h2 { width:100%; }
.one h2 img{
width:200px;
height:200px;
border-radius:50%;
margin:0 0 0 -100px;
left:50%;
top:100px;
display:block;
position:absolute;
}
.animated {
animation-duration:3s;
-webkit-animation-duration:3s;
-webkit-animation-fill-mode: both;
animation-fill-mode: both;
}
.xuanzhuan { animation-name:xuanzhuan; -webkit-animation-name:xuanzhuan;}
@keyframes xuanzhuan {
0% { opacity:0; transform:rotate(120deg);-webkit-transform:rotate(120deg);}
50% { opacity:0.5; transform:scale(1.5,1.5);-webkit-transform:scale(1.5,1.5);}
100% { opacity:1; transform: scale(1,1);-webkit-transform:scale(1,1);}
}
@-webkit-keyframes xuanzhuan {
0% { opacity:0; transform:rotate(120deg);-webkit-transform:rotate(120deg);}
50% { opacity:0.5; transform:scale(1.5,1.5);-webkit-transform:scale(1.5,1.5);}
100% { opacity:1; transform:scale(1,1);-webkit-transform:scale(1,1);}
}
</style>
<script>
function getTop(clsName){
var obj = document.getElementsByClassName(clsName)[0];
return obj.getBoundingClientRect().top;
}
function getDom(clsName){
var obj=document.getElementsByClassName(clsName)[0];
return obj;
}
window.addEventListener(‘scroll‘,function(){
var scrollT=document.documentElement.scrollTop||document.body.scrollTop;
/*第二页动画的触发*/
if(getTop(‘one‘)<100){
getDom(‘img01‘).classList.add(‘animated‘);//注意这个
getDom(‘img01‘).classList.add(‘xuanzhuan‘);
}
})
</script>
</head>
<body>
<div class="box">
<div class="two"></div>
<div class="one">
<h2><img class="img01" src="images/about.png" /></h2>
</div>
</div>
</body>
</html>
以上是关于鼠标滑动到当前页面触发动画效果的主要内容,如果未能解决你的问题,请参考以下文章
jquery如何animate防止叠加 例如我把鼠标不断移入移出 效果就会不断重复,如何防止呢?