directive.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. starter.directive('task', [function () {
  2. return {
  3. restrict: "E",
  4. scope: {
  5. data: "=source"
  6. },
  7. templateUrl: 'templates/template-task.html',
  8. controller: function ($scope) {
  9. if ($scope.data.end_dd != null) {
  10. $scope.data.end_dd = new Date($scope.data.end_dd);
  11. $scope.date = new Date();
  12. var startTime = new Date(Date.parse($scope.data.end_dd)).getTime();
  13. var endTime = new Date(Date.parse($scope.date)).getTime();
  14. var dates = Math.floor((endTime - startTime) / (1000 * 60 * 60 * 24));
  15. if (($scope.data.end_dd < $scope.date && dates != 0) && $scope.data.is_completed == 0) {
  16. $scope.node = '过期' + dates + '天';
  17. $scope.flag = true;
  18. } else {
  19. $scope.node = '截止';
  20. $scope.flag = false;
  21. }
  22. }
  23. $scope.showcardinfo = function (id) {
  24. console.log(id);
  25. }
  26. }
  27. }
  28. }])
  29. .directive('scrollpin', function ($window) {
  30. return {
  31. link: function (scope, element, attrs) {
  32. angular.element($window).on('scroll', onScroll);
  33. function onScroll() {
  34. var offset = $window.pageYOffset;
  35. var offsetTop = element[0].offsetTop;
  36. var before = element[0].previousElementSibling;
  37. if (offsetTop < offset) {
  38. var move = parseInt(attrs.scrollpin || 0) + offsetTop - offset;
  39. before.style.position = 'fixed';
  40. if (move < 0 && -move < parseInt(attrs.scrollpin)) {
  41. before.style.top = move + 'px';
  42. } else {
  43. before.style.top = '0';
  44. }
  45. } else {
  46. before.style.position = 'absolute';
  47. before.style.top = '';
  48. }
  49. }
  50. }
  51. };
  52. });