Advertisement
Guest User

Untitled

a guest
Jul 1st, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var App = {
  2.     init: function() {
  3.         $(".auth .head a").click(function() {
  4.             App.changeContent($(this));
  5.         });
  6.     },
  7.  
  8.     changeContent: function($dom) {
  9.         var trigger  = $dom.data("trigger");
  10.         var $content = this.getContent(trigger);
  11.  
  12.         $(".auth .content").addClass("hidden"); // Hide all contents
  13.         $content.removeClass("hidden"); // Show wanted content
  14.  
  15.         $(".auth .head a").removeClass("active");
  16.         $(".auth .head a[data-trigger='"+trigger+"']").addClass("active");
  17.     },
  18.  
  19.     getContent: function(type) {
  20.         return $(".auth .content[data-type='"+type+"']");
  21.     }
  22. }
  23.  
  24. var OnePage = {
  25.     init: function() {
  26.         // Reset sections
  27.         this.scrollTo(this.getCurrentSection());
  28.  
  29.         $("body#onePage").bind("mousewheel", function(e){
  30.             if (e.originalEvent.wheelDelta /120 > 0) {
  31.                 // Scroll up
  32.                 if (OnePage.getPreviousSection()) {
  33.                     OnePage.scrollTo(OnePage.getPreviousSection());
  34.                 }
  35.  
  36.                 return false;
  37.             } else{
  38.                 // Scroll down
  39.                 if (OnePage.getNextSection()) {
  40.                     OnePage.scrollTo(OnePage.getNextSection());
  41.                 }
  42.  
  43.                 return false;
  44.             }
  45.         });
  46.     },
  47.  
  48.     getCurrentSection: function() {
  49.         return $("section.active");
  50.     },
  51.  
  52.     getNextSection: function() {
  53.         if (this.isSection(this.getCurrentSection().next())) {
  54.             return this.getCurrentSection().next();
  55.         }
  56.  
  57.         return false;
  58.     },
  59.  
  60.     getPreviousSection: function() {
  61.         if (this.isSection(this.getCurrentSection().prev())) {
  62.             return this.getCurrentSection().prev();
  63.         }
  64.  
  65.         return false;
  66.     },
  67.  
  68.     isSection: function($dom) {
  69.         return $dom.is("section");
  70.     },
  71.  
  72.     scrollTo: function($dom) {
  73.         if (!$("html, body").is(":animated")) {
  74.             $("html, body").animate({
  75.                 scrollTop: parseInt($dom.position().top)
  76.             }, speed);
  77.  
  78.             this.getCurrentSection().removeClass("active");
  79.             $dom.addClass("active");
  80.         }
  81.     },
  82. }
  83.  
  84. App.init();
  85. OnePage.init();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement