-
Notifications
You must be signed in to change notification settings - Fork 78
/
example.html
107 lines (94 loc) · 3.32 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>AngularJS Scroll Glue Directive</title>
<style type="text/css">
[scroll-glue-top],
[scroll-glue-bottom],
[scroll-glue]{
height: 100px;
overflow-y: scroll;
border: 1px solid gray;
}
[scroll-glue-left],
[scroll-glue-right]{
width: 100px;
overflow-x: scroll;
border: 1px solid gray;
padding: 10px;
}
[scroll-glue-left] span,
[scroll-glue-right] span{
border: 1px solid black;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.js"></script>
<script src="src/scrollglue.js"></script>
<script>
angular
.module('demo', ['luegg.directives'])
.controller('ItemsCtrl', function ItemsCtrl($scope, $timeout){
$scope.items = ['1', '2', '3'];
var counter = $scope.items.slice(-1)[0];
$scope.glued = true;
function addItem(){
$scope.items.push(++counter);
$timeout(addItem, 1000);
}
$timeout(addItem, 1000);
});
</script>
</head>
<body ng-app="demo" ng-controller="ItemsCtrl">
<h1>Simple</h1>
<p>To activate the scroll glue on an element just add the scroll-glue attribute.</p>
<pre><div scroll-glue/></pre>
<div scroll-glue>
<ul>
<li ng-repeat="item in items">{{item}}</li>
</ul>
</div>
<h1>With two-way data binding</h1>
<p>If you pass a scope variable to the attribute, scroll-glue updates the variable to true when the glue is attached or to false if the glue is released and activates/deactivates the glue according to the variables value.</p>
<pre><div scroll-glue="glued"/></pre>
<div scroll-glue="glued">
<ul>
<li ng-repeat="item in items">{{item}}</li>
</ul>
</div>
<p><button ng-click="glued = !glued">Toggle glued ({{glued}})</button></p>
<h1>With one-way data binding</h1>
<p>If you pass an expression that is not a scope variable, the scroll-glue is bound to the result of this expression.</p>
<pre><div scroll-glue="!glued"/></pre>
<div scroll-glue="!glued">
<ul>
<li ng-repeat="item in items">{{item}}</li>
</ul>
</div>
<p>If you want to force one way-binding on a scope variable use double negation:</p>
<pre><div scroll-glue="!!glued"/></pre>
<h1>Scroll Direction</h1>
<p>You can also specify the scroll direction by combining the following directives:</p>
<pre><div scroll-glue-top="glued"/></pre>
<div scroll-glue-top="glued">
<ul>
<li ng-repeat="item in items.slice().reverse()">{{item}}</li>
</ul>
</div>
<pre><div scroll-glue-bottom="glued"/></pre>
<div scroll-glue-bottom="glued">
<ul>
<li ng-repeat="item in items">{{item}}</li>
</ul>
</div>
<pre><div scroll-glue-left="glued"/></pre>
<div scroll-glue-left="glued">
<span ng-repeat="item in items.slice().reverse()">{{item}}</span>
</div>
<pre><div scroll-glue-right="glued"/></pre>
<div scroll-glue-right="glued">
<span ng-repeat="item in items">{{item}}</span>
</div>
</body>
</html>