今天来跟大家分享一个小的demo,一般网页浏览到底部的时候会有一个点击加载更多的按钮,之前一直纠结怎么写这个,今天学习angular时发现可以用组件来实现这么一个小的效果,大家有兴趣的话可以看一下。

点击加载更多,代码如下:

<!DOCTYPE html>
<html ng-app="indexApp">//绑定模块
<head>
<meta charset="UTF-8">
<title></title>
<style>
#fixed{
height: 500px;
overflow: auto;
}
</style>
<script src="../js/angular.1.5.6.js"></script>//引入angular库
<script>
var app = angular.module('indexApp',[]);//定义模块
app.controller('indexCtrl',['$scope',function($scope){//定义控制器
$scope.items = ['a','b'];
for(var i=0;i<=30;i++){
$scope.items.push(Math.random()*10);
}
$scope.loca = function(){
for(var j=0;j<=10;j++){
$scope.items.push(Math.random()*10);
}
} }]);
app.directive('ngScroll',function(){//组件
return {
template:'<ul><li ng-repeat="item in items">{{item}}</li></ul>',
}
});
</script>
</head>
<body>
<div ng-controller="indexCtrl">
<div id="fixed" ng-scroll=""></div><!--指令的方式-->
<button ng-click="loca()">查看更多</button>
</div>
</body>
</html> 滑动到底部自动加载:
<!DOCTYPE html>
<html ng-app="loadMoreApp">
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <style>
        #fixed {
            height: 500px;
            overflow: auto;/*溢出显示滚动条*/
        }
    </style>
    <body>
        <div ng-controller="indexCtrl">
            <div id="fixed" ng-scroll="loadMore()"><!--指令的方式-->
                
            </div>
        </div>
    </body>
    <script src="js/angular.js"></script>
    <script>
        var app = angular.module('loadMoreApp', []);//定义一个模块
        app.controller('indexCtrl', ['$scope', function($scope) {//定义一个控制器
            $scope.items = ['a', 'b'];
            var i = 0;
            for(; i <= 30; i++) {
                $scope.items.push(Math.random() * 10);//生成随机数,加到items这个数组后
            }
            $scope.loadMore = function() {
                var j = 0;
                for(; j <= 10; j++) {
                    $scope.items.push(Math.random() * 10);
                }
            }
            
        }]);
        //定义一个组件
        app.directive('ngScroll', [function() {
            return {
                template: '<ul><li ng-repeat="item in items">{{item}}</li></ul>',
                link: function(scope, ele, attr) {
                    //                    console.log(ele);
                    ele.bind('scroll', function(e) {
//                        console.log("offsetHeight:" + e.target.offsetHeight)
//                        console.log("scrollTop:" + e.target.scrollTop) //滚动的距离
//                        console.log("scrollHeight" + e.target.scrollHeight)
                        if(e.target.offsetHeight + e.target.scrollTop >= e.target.scrollHeight) {
                            console.log("你已经到底了")
                            scope.$apply(attr.ngScroll);
                        }
                    })
                }
            }
        }])
    </script>
</html>

angular点击查看更多(简单demo)的更多相关文章

  1. 利用ScrollView滑动属性实现点击查看更多

    利用ScrollView的滚动实现点击查看更多 效果图 更新内容布局 <ScrollView android:id="@+id/sv_des" android:layout_ ...

  2. JS点击查看更多内容 控制段落文字展开折叠

    JavaScript+jQuery实现的文字展开折叠效果,点击文字后文字内容会完整的显示出来,控制段落来显示文字,不需要的时候,可以再次点击后将内容折叠起来,也就是隐藏了一部分内容.点击查看更多的功能 ...

  3. jquery 点击查看更多箭头变化,文字变化,超出带滚动条。

    从网上好了好久,没找到自己要的,自己写了一下. <!DOCTYPE html> <html> <head> <meta charset="utf-8 ...

  4. jQ-点击查看更多

    <style type="text/css"> .hi { width: 200px; height: 18vw; background-color: pink; fo ...

  5. angular实现了一个简单demo,angular-weibo-favorites

    前面必须说一段 帮客户做了一个过渡期的项目,唯一的要求就是速度,我只是会点儿基础的php,于是就用tp帮客户做了这个项目.最近和客户架构沟通,后期想把项目重新做一下,就用现在最流行的技术,暂时想的使用 ...

  6. Deferred在jQuery和Angular中的使用与简单实现

    Deferred在jQuery和Angular中的使用与简单实现 Deferred是在jQuery1.5版本中加入的,并且jQuery使用它完全重写了AJax,以前也只是偶尔使用.但是上次在使用Ang ...

  7. iOS中"查看更多/收起"功能实现

    实现效果如图: 查看更多功能在很多app种都有应用,在这里简单的实现,介绍实现流程: 一个tableViewCell中包含一个collectionView,"查看更多"按钮是tab ...

  8. Spring的简单demo

    ---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...

  9. jquery 点击显示更多

    点击显示更多 html <div class="servicepicture banxin"> <div class="imgcontent" ...

随机推荐

  1. RuntimeError: module compiled against API version 0xb but this version of numpy is 0xa

    两个python,一个是本机自带的,一个是anaconda.先前呢,用自带的安装了Opencv,由于自带的python,对应的numpy版本是13, 而anaconda对应的版本是12,导致impor ...

  2. “帮你”APP——NABCD需求分析

    1.你的创意解决了用户的什么需求?(N) 本学校已存在的失物招领.表白墙.二手市场等QQ群普遍存在信息冗杂,时效性差等缺点.不能充分发挥信息有效性的,我们的“帮你”APP能够充分发挥信息的有效性,让失 ...

  3. sql语句应用

    laravel5.6框架中用到的sql语句 //排序 $data=DB::table('admin')->select(array('id','name','password'))->or ...

  4. elasticsearch增删查改

    创建结构化索引 put http://127.0.0.1:9200/person{ "settings" : { "number_of_shards": 3, ...

  5. vscode垂直选中列选中

    VSCode列选择快捷键:Alt+Shift+左键

  6. 循环列表最后一条不显示borderBottom

    You could achieve this using some logic: return books.map((book, i) => { return( <View style={ ...

  7. 同时安装 Python 2 与Python 3 的方法及pip模块的下载安装

    Python虽然功能强大,上手容易,但版本问题却是个烦人的问题. Python 2.x 和 Python 3.x 版本之间存在很大的不兼容. 同时安装Python2.x和Python3.x 1. 在P ...

  8. ceph-deploy部署过程

    [root@ceph-1 my_cluster]# ceph-deploy --overwrite-conf osd create ceph-1 --data data_vg1/data_lv1 -- ...

  9. day47 选择器优先级及嵌套关系

    复习 1.前端: 网页, html + css + js 2.html三个组成部分:标签,指令和转义字符 标签: <>包裹, 以字母开头, 可以结合-|数字, 能被浏览器解析的标记 3.常 ...

  10. 【题解二连发】Construct Binary Tree from Inorder and Postorder Traversal & Construct Binary Tree from Preorder and Inorder Traversal

    LeetCode 原题链接 Construct Binary Tree from Inorder and Postorder Traversal - LeetCode Construct Binary ...