码迷,mamicode.com
首页 > 其他好文 > 详细

鼠标滑动到当前页面触发动画效果

时间:2018-09-26 22:12:32      阅读:498      评论:0      收藏:0      [点我收藏+]

标签:block   type   orange   动画   meta   1.5   ima   abs   top   

<!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>

鼠标滑动到当前页面触发动画效果

标签:block   type   orange   动画   meta   1.5   ima   abs   top   

原文地址:https://www.cnblogs.com/xiaoruaning/p/9709944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!