AngularJS实现的回到顶部指令功能实例-创新互联

本文实例讲述了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" 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>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
   <h2>hello world</h2>
 </body>
</html>

另外有需要云服务器可以了解下创新互联建站www.cdcxhl.com,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。

网站标题:AngularJS实现的回到顶部指令功能实例-创新互联
文章位置:https://www.cdcxhl.com/article32/cshcsc.html

成都网站建设公司_创新互联,为您提供定制网站企业建站响应式网站手机网站建设电子商务网站收录

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站网页设计