angular点击查看更多(简单demo)
今天来跟大家分享一个小的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)的更多相关文章
- 利用ScrollView滑动属性实现点击查看更多
利用ScrollView的滚动实现点击查看更多 效果图 更新内容布局 <ScrollView android:id="@+id/sv_des" android:layout_ ...
- JS点击查看更多内容 控制段落文字展开折叠
JavaScript+jQuery实现的文字展开折叠效果,点击文字后文字内容会完整的显示出来,控制段落来显示文字,不需要的时候,可以再次点击后将内容折叠起来,也就是隐藏了一部分内容.点击查看更多的功能 ...
- jquery 点击查看更多箭头变化,文字变化,超出带滚动条。
从网上好了好久,没找到自己要的,自己写了一下. <!DOCTYPE html> <html> <head> <meta charset="utf-8 ...
- jQ-点击查看更多
<style type="text/css"> .hi { width: 200px; height: 18vw; background-color: pink; fo ...
- angular实现了一个简单demo,angular-weibo-favorites
前面必须说一段 帮客户做了一个过渡期的项目,唯一的要求就是速度,我只是会点儿基础的php,于是就用tp帮客户做了这个项目.最近和客户架构沟通,后期想把项目重新做一下,就用现在最流行的技术,暂时想的使用 ...
- Deferred在jQuery和Angular中的使用与简单实现
Deferred在jQuery和Angular中的使用与简单实现 Deferred是在jQuery1.5版本中加入的,并且jQuery使用它完全重写了AJax,以前也只是偶尔使用.但是上次在使用Ang ...
- iOS中"查看更多/收起"功能实现
实现效果如图: 查看更多功能在很多app种都有应用,在这里简单的实现,介绍实现流程: 一个tableViewCell中包含一个collectionView,"查看更多"按钮是tab ...
- Spring的简单demo
---------------------------------------- 开发一个Spring的简单Demo,具体的步骤如下: 1.构造一个maven项目 2.在maven项目的pom.xml ...
- jquery 点击显示更多
点击显示更多 html <div class="servicepicture banxin"> <div class="imgcontent" ...
随机推荐
- leetcode971
class Solution: def flipMatchVoyage(self, root, voyage): res = [] self.i = 0 def dfs(root): if not r ...
- JAVA并发-基于AQS实现自己的显示锁
一.了解什么是AQS 原文链接:http://www.studyshare.cn/blog-front/blog/details/1131 AQS是AbstractQueuedSynchronizer ...
- Python module ---- abc
python中并没有提供抽象类与抽象方法,但是提供了内置模块abc(abstract base class)来模拟实现抽象类. ABC,Abstract Base Class(抽象基类),主要定义了 ...
- python回归分析
假设原函数由一个三角函数和一个线性项组成 import numpy as np import matplotlib.pyplot as plt %matplotlib inline def f(x): ...
- groovy 知识集锦
对应官方的<Program structure>的中文翻译 http://www.cnblogs.com/zhaoxia0815/p/7404387.html
- [SF] Symfony 在 console 中结合 Workerman
在web框架的console中,命令不再是直接指定入口文件,如以往 php test.php start,而是类似 php app/console do 的形式. workerman 对命令的解析是 ...
- Arthas的基础学习
下载与安装 wget https://alibaba.github.io/arthas/arthas-boot.jar java -jar arthas-boot.jar 启动 查看启动的帮助信息: ...
- [Solution] 893. Groups of Special-Equivalent Strings
Difficulty: Easy Problem You are given an array A of strings. Two strings S and T are special-equiva ...
- DIV+CSS详解
DIV+CSS详解 ✪DIV+CSS"这种叫法其实是一种不准确的叫法 在做笔记的最前面必须先给大家纠正一个错误,就是"DIV+CSS"这种叫法其实是一种不准确的叫法,是国 ...
- c++ vector push_back对象的时候存起来的是拷贝
比如 class C1; vector<C1> vec;C1* p=new C1;vec v1;v1.push_back(&(*p));delete p; 这里,传进函数的是引用, ...