jquery 滾動到指定位置觸發動畫
阿新 • • 發佈:2019-02-15
jQuery 滾動到指定位置觸發動畫
- <!doctype html>
- <html>
- <head>
- <metacharset="utf-8">
- <title>sas</title>
- <scripttype="text/javascript"src="js/jquery.js"></script>
- <styletype="text/css">
- *{ margin:0px; padding:0px;}
- .gs{
- position:relative;
- top:800px;
- background-color:#099;
- left:150px; width:80px;
- }
- .xz{
- animation:roate 2s;
- animation-fill-mode:forwards;
- animation-direction:alternate;
- }
- @keyframes roate{
- from { transform:rotate(0deg);
- width:100px;
- height:100px; }
- to{transform:rotate(360deg);
- width:200px;
- height:200px;
- }}
- .xs{ width:50px; float: left; height:30px; background-color: #F90; position:fixed; left:700px; top:0px;}
- </style>
- </head>
- <body>
- <scripttype="text/javascript">
- function gdjz(div,cssname,offset){
- var a,b,c,d;
- d=$(div).offset().top;
- a=eval(d + offset);
- b=$(window).scrollTop();
- c=$(window).height();
- if(b+c>a){
- $((div)).addClass((cssname));
- }
- }
- $(document).ready(function(e) {
- $(window).scroll(function(){
- gdjz("#dh",'xz',100);
- }
- /*var a,b,c;
- a=$("#dh").offset().top;//元素相對於視窗的距離
- b=$(window).scrollTop(); //監控視窗已滾動的距離;
- c=$(document).height();//整個文件的高度
- d=$(window).height();//瀏覽器視窗的高度*/
- /*if(d+b>a+100){
- $("#dh").addClass("xz");
- }
- */
- );
- });
- </script>
- <divstyle="height:1800px; background-color:#999; width:500px; float:left;">
- <divid="dh"class="gs">觸發動畫</div>
- </div>
- <divclass="xs"></div>
- </body>
- </html>