利用jquery制作滾動到指定位置觸發(fā)動畫
更新時間:2016年03月26日 10:12:46 作者:260kk
本文只是一個簡單的演示程序,大家可以根據自己的需求進行修改,以達到自己想要實現的功能。
利用CSS3的 animation 動畫特性來完成的,對IE的兼容性不是太好,適用與手機端。
<!doctype html> <html> <head> <meta charset="utf-8"> <title>sas</title> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.9.1/jquery.min.js"></script> <style type="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> <script type="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',500); } /*var a,b,c; a=$("#dh").offset().top;//元素相對于窗口的距離 b=$(window).scrollTop(); //監(jiān)控窗口已滾動的距離; c=$(document).height();//整個文檔的高度 d=$(window).height();//瀏覽器窗口的高度*/ /*if(d+b>a+100){ $("#dh").addClass("xz"); } */ ); }); </script> <div style="height:1800px; background-color:#999; width:500px; float:left;"> <div id="dh" class="gs" >觸發(fā)動畫</div> </div> <div class="xs"></div> </body> </html>
相關文章
asp.net+jquery.form實現圖片異步上傳的方法(附jquery.form.js下載)
這篇文章主要介紹了asp.net+jquery.form實現圖片異步上傳的方法,結合實例形式分析了jquery.form.js前臺異步提交圖片與asp.net后臺處理的相關技巧,需要的朋友可以參考下2016-05-05jQuery在ie6下無法設置select選中的解決方法詳解
這篇文章主要介紹了jQuery在ie6下無法設置select選中的解決方法,結合實例分析了jQuery在ie6下無法設置select選中的原因與相關處理技巧,需要的朋友可以參考下2016-09-09深入淺析ng-bootstrap 組件集中 tabset 組件的實現分析
這篇文章主要介紹了ng-bootstrap 組件集中 tabset 組件的實現分析 ,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07