Tema: Multiscroll
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 30/05/2014, 10:01
Avatar de satjaen
satjaen
 
Fecha de Ingreso: septiembre-2012
Ubicación: Jaén (Andalucía)
Mensajes: 893
Antigüedad: 11 años, 8 meses
Puntos: 10
Respuesta: Multiscroll

Continuacion....

Código Javascript:
Ver original
  1. //navigation tooltips
  2.         $(document).on({
  3.             mouseenter: function(){
  4.                 var tooltip = $(this).data('tooltip');
  5.                 $('<div class="multiscroll-tooltip ' + options.navigationPosition +'">' + tooltip + '</div>').hide().appendTo($(this)).fadeIn(200);
  6.             },
  7.             mouseleave: function(){
  8.                 $(this).find('.multiscroll-tooltip').fadeOut().remove();
  9.             }
  10.         }, '#multiscroll-nav li');
  11.  
  12.  
  13.         if(options.normalScrollElements){
  14.             $(document).on('mouseover', options.normalScrollElements, function () {
  15.                 $.fn.multiscroll.setMouseWheelScrolling(false);
  16.             });
  17.            
  18.             $(document).on('mouseout', options.normalScrollElements, function(){
  19.                 $.fn.multiscroll.setMouseWheelScrolling(true);
  20.             });
  21.         }
  22.  
  23.  
  24.         //when resizing the site, we adjust the heights of the sections
  25.         $(window).resize(function() {
  26.             doneResizing();
  27.         });
  28.  
  29.         /**
  30.          * When resizing is finished, we adjust the slides sizes and positions
  31.          */
  32.         function doneResizing() {
  33.             windowHeight = $(window).height();
  34.  
  35.             silentScroll();
  36.             $.isFunction( options.afterResize ) && options.afterResize.call( this);
  37.         }
  38.  
  39.         function silentScroll(){
  40.             //moving the right section to the bottom
  41.             if(options.css3){
  42.                 transformContainer($('.ms-left'), 'translate3d(0px, -' + $('.ms-left').find('.ms-section.active').position().top + 'px, 0px)', false);
  43.                 transformContainer($('.ms-right'), 'translate3d(0px, -' + $('.ms-right').find('.ms-section.active').position().top + 'px, 0px)', false);
  44.             }else{
  45.                 $('.ms-left').css('top', -$('.ms-left').find('.ms-section.active').position().top );
  46.                 $('.ms-right').css('top', -$('.ms-right').find('.ms-section.active').position().top );
  47.             }
  48.         }
  49.  
  50.         $.fn.multiscroll.moveSectionUp = function(){
  51.             var prev = $('.ms-left .ms-section.active').prev('.ms-section');
  52.  
  53.             if(!prev.length && options.loopTop){
  54.                 prev = $('.ms-left .ms-section').last();
  55.             }
  56.  
  57.             if (prev.length) {
  58.                 scrollPage(prev);
  59.             }
  60.         };
  61.  
  62.         $.fn.multiscroll.moveSectionDown = function (){
  63.             var next = $('.ms-left .ms-section.active').next('.ms-section');
  64.  
  65.             if(!next.length && options.loopBottom ){
  66.                 next = $('.ms-left .ms-section').first();
  67.             }
  68.  
  69.             if(next.length){
  70.                 scrollPage(next);
  71.             }
  72.         };
  73.  
  74.         $.fn.multiscroll.moveTo = function (section){
  75.             var destiny = '';
  76.            
  77.             if(isNaN(section)){
  78.                 destiny = $('.ms-left [data-anchor="'+section+'"]');
  79.             }else{
  80.                 destiny = $('.ms-left .ms-section').eq( (section -1) );
  81.             }
  82.            
  83.             scrollPage(destiny);
  84.         };
  85.  
  86.         function scrollPage(leftDestination){
  87.             var leftDestinationIndex = leftDestination.index();
  88.             var rightDestination = $('.ms-right').find('.ms-section').eq( numberSections -1 - leftDestinationIndex);
  89.             var rightDestinationIndex = numberSections - 1 - leftDestinationIndex;
  90.             var anchorLink  = leftDestination.data('anchor');
  91.             var activeSection = $('.ms-left .ms-section.active');
  92.             var leavingSection = activeSection.index() + 1;
  93.             var yMovement = getYmovement(leftDestination);
  94.  
  95.             //preventing from activating the MouseWheelHandler event
  96.             //more than once if the page is scrolling
  97.             isMoving = true;
  98.  
  99.             setURLHash(anchorLink);
  100.  
  101.             var topPos = {
  102.                 'left' : leftDestination.position().top,
  103.                 'right': rightDestination.position().top
  104.             };
  105.  
  106.             rightDestination.addClass('active').siblings().removeClass('active');
  107.             leftDestination.addClass('active').siblings().removeClass('active');
  108.  
  109.             // Use CSS3 translate functionality or...
  110.             if (options.css3){             
  111.                 //callback (onLeave)
  112.                 $.isFunction(options.onLeave) && options.onLeave.call(this, leavingSection, (leftDestinationIndex + 1), yMovement);
  113.  
  114.                 var translate3dLeft = 'translate3d(0px, -' + topPos['left'] + 'px, 0px)';
  115.                 var translate3dRight = 'translate3d(0px, -' + topPos['right'] + 'px, 0px)';
  116.  
  117.                 transformContainer($('.ms-left'), translate3dLeft, true);
  118.                 transformContainer($('.ms-right'), translate3dRight, true);
  119.  
  120.                 setTimeout(function () {
  121.                     //callback (afterLoad)
  122.                     $.isFunction(options.afterLoad) && options.afterLoad.call(this, anchorLink, (leftDestinationIndex + 1));
  123.  
  124.                     setTimeout(function () {
  125.                         isMoving = false;
  126.                     }, scrollDelay);
  127.                 }, options.scrollingSpeed);
  128.             }else{
  129.                 //callback (onLeave)
  130.                 $.isFunction(options.onLeave) && options.onLeave.call(this, leavingSection, (leftDestinationIndex + 1), yMovement);
  131.  
  132.                 $('.ms-left').animate({
  133.                     'top': -topPos['left']
  134.                 }, options.scrollingSpeed, options.easing, function(){
  135.                     $.isFunction(options.afterLoad) && options.afterLoad.call(this, anchorLink, (leftDestinationIndex + 1));
  136.  
  137.                     setTimeout(function () {
  138.                         isMoving = false;
  139.                     }, scrollDelay);
  140.                 });
  141.  
  142.                 $('.ms-right').animate({
  143.                     'top': -topPos['right']
  144.                 }, options.scrollingSpeed, options.easing);
  145.             }
  146.            
  147.             //flag to avoid callingn `scrollPage()` twice in case of using anchor links
  148.             lastScrolledDestiny = anchorLink;
  149.  
  150.             activateMenuElement(anchorLink);
  151.             activateNavDots(anchorLink, leftDestinationIndex);
  152.         }
  153.  
  154.         /**
  155.         * Removes the auto scrolling action fired by the mouse wheel and tackpad.
  156.         * After this function is called, the mousewheel and trackpad movements won't scroll through sections.
  157.         */
  158.         function removeMouseWheelHandler(){
  159.             if (document.addEventListener) {
  160.                 document.removeEventListener('mousewheel', MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
  161.                 document.removeEventListener('wheel', MouseWheelHandler, false); //Firefox
  162.             } else {
  163.                 document.detachEvent("onmousewheel", MouseWheelHandler); //IE 6/7/8
  164.             }
  165.         }
  166.  
  167.         /**
  168.         * Adds the auto scrolling action for the mouse wheel and tackpad.
  169.         * After this function is called, the mousewheel and trackpad movements will scroll through sections
  170.         */
  171.         function addMouseWheelHandler(){
  172.             if (document.addEventListener) {
  173.                 document.addEventListener("mousewheel", MouseWheelHandler, false); //IE9, Chrome, Safari, Oper
  174.                 document.addEventListener("wheel", MouseWheelHandler, false); //Firefox
  175.             } else {
  176.                 document.attachEvent("onmousewheel", MouseWheelHandler); //IE 6/7/8
  177.             }
  178.         }
  179.  
  180.         /**
  181.          * Detecting mousewheel scrolling
  182.          *
  183.          * http://blogs.sitepointstatic.com/examples/tech/mouse-wheel/index.html
  184.          * http://www.sitepoint.com/html5-javascript-mouse-wheel/
  185.          */
  186.         function MouseWheelHandler(e) {
  187.             // cross-browser wheel delta
  188.             e = window.event || e;
  189.             var delta = Math.max(-1, Math.min(1,
  190.                     (e.wheelDelta || -e.deltaY || -e.detail)));
  191.  
  192.             if (!isMoving) { //if theres any #
  193.  
  194.                 //scrolling down?
  195.                 if (delta < 0) {
  196.                     $.fn.multiscroll.moveSectionDown();
  197.                 }
  198.  
  199.                 //scrolling up?
  200.                 else {
  201.                     $.fn.multiscroll.moveSectionUp();
  202.                 }
  203.             }
  204.        
  205.  
  206.             return false;
  207.         }
  208.  
  209.     /**
  210.         * Adds a css3 transform property to the container class with or without animation depending on the animated param.
  211.         */
  212.         function transformContainer(container, translate3d, animated){
  213.             container.toggleClass('ms-easing', animated);
  214.            
  215.             container.css(getTransforms(translate3d));
  216.         }