Advertisement
Guest User

Untitled

a guest
Jan 26th, 2015
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. var PictureScroller = (function () {
  2. var self;
  3.  
  4. function PictureScroller ($el) {
  5. self = this;
  6.  
  7. self.$parent = $el.parent();
  8. self.$el = $el;
  9. self.$floatingContent = $el.find('.floating-content');
  10. self.$pictures = $el.find('.pic');
  11. self.$activePicture;
  12. self.$dots = self.$floatingContent.find('.dotstyle li');
  13.  
  14. console.log(self.$dots);
  15.  
  16. self.bind();
  17. }
  18.  
  19. PictureScroller.prototype.bind = function() {
  20. self.$parent.waypoint(function(direction) {
  21. self.hitTop(direction);
  22. });
  23.  
  24. self.$parent.waypoint(function(direction) {
  25. self.hitBottom(direction);
  26. }, {
  27. offset: function() {
  28. return -$(this).height() + $(self.$floatingContent).height() + 80;
  29. }
  30. });
  31.  
  32. self.$pictures.waypoint(function(direction) {
  33. if(direction === 'down')
  34. self.hitPicture($(this));
  35. }, {
  36. offset: + $(self.$pictures[0]).height() / 2
  37. });
  38.  
  39. self.$pictures.waypoint(function(direction) {
  40. if(direction === 'up')
  41. self.hitPicture($(this));
  42. }, {
  43. offset: - $(self.$pictures[0]).height() / 2
  44. });
  45. };
  46.  
  47. PictureScroller.prototype.hitTop = function(direction) {
  48. console.log('hit top');
  49. if(direction === 'down')
  50. $(self.$floatingContent).addClass('js-fixed');
  51.  
  52. if(direction === 'up')
  53. $(self.$floatingContent).removeClass('js-fixed');
  54.  
  55. };
  56.  
  57. PictureScroller.prototype.hitBottom = function(direction) {
  58. console.log('hit bottom');
  59. if(direction === 'down')
  60. $(self.$floatingContent).addClass('js-station-bottom').removeClass('js-fixed');
  61.  
  62. if(direction === 'up')
  63. $(self.$floatingContent).removeClass('js-station-bottom').addClass('js-fixed');
  64. };
  65.  
  66. PictureScroller.prototype.hitPicture = function(picture) {
  67. var currentPictureID = picture.attr('data-picture-id');
  68.  
  69. if(self.$activePicture !== undefined)
  70. self.$activePicture.removeClass('js-ps-active');
  71. $('.dotstyle li.current').removeClass('current');
  72. $(self.$dots[currentPictureID]).addClass('current');
  73.  
  74. self.$activePicture = $(picture);
  75. self.$activePicture.addClass('js-ps-active');
  76. };
  77.  
  78. return PictureScroller;
  79.  
  80. }());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement