example.html 3.3 KB

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