早上好,给您新鲜的问候,温暖的祝福,清晨,美好的开端,祝您今天精神振奋,精力充沛,心情愉快,一切都很好!
本文实例讲述了AngularJS实现的回到顶部指令功能。分享给大家供大家参考,具体如下:
<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" rel="nofollow noopener noreferrer" href="bootstrap.min.css" rel="external nofollow" > <script src="jquery.min.js"></script> <script src="angular.js"></script> <script src="bootstrap.min.js"></script> <style type="text/css"> #gotoTop { display: none; position: fixed; top: 80%; left: 90%; cursor: pointer; padding: 4px 4px; width: 50px; border: 1px solid #e0e0e0; background: #fff; border-radius: 50px; height: 50px; } #gotoTop.hover { background: #e0e0e0; color: #fff; text-decoration: none; } .arrow { width: 0; height: 0; margin: 0 auto; border: 9px solid transparent; border-bottom-color: #aaa; } .stick { width: 8px; height: 14px; margin: 0 auto; border-radius: 1px; background-color: #aaa; } </style> <script type="text/javascript"> var myapp = angular.module('myapp', []); myapp.directive("goToTop", function() { return { restrict: 'E', replace: true, scope: { minHeight : '@' }, templateUrl : 'tmpl.html', link: function(scope, elem, attrs) { elem.click(function() { jQuery('html,body').animate({scrollTop:0}, 700); }) .hover(function() { jQuery(this).addClass("hover"); }, function() { jQuery(this).removeClass("hover"); }); scope.minHeight = scope.minHeight ? scope.minHeight : 600; jQuery(window).scroll(function() { var s = jQuery(window).scrollTop(); if( s > scope.minHeight) { jQuery("#gotoTop").fadeIn(100); } else { jQuery("#gotoTop").fadeOut(200); }; }); } }; }); </script> </head> <body ng-app="myapp"> <go-to-top min-height="800"></go-to-top> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> <h1>hello world</h1> </body> </html>
tmpl.html
<div id="gotoTop" title="返回顶部"> <div class="arrow"></div> <div class="stick"></div> </div>
希望本文所述对大家AngularJS程序设计有所帮助。
本文AngularJS实现的回到顶部指令功能实例到此结束。当你被失败拥抱时,成功可能正在一边等着吻你。小编再次感谢大家对我们的支持!