Team:Heidelberg/js/frontpage

From 2014.igem.org

(Difference between revisions)
Line 58: Line 58:
   setTweenParams(moveRing);
   setTweenParams(moveRing);
   scene.setTween(timeline);
   scene.setTween(timeline);
-
   $docH = $(document).outerHeight() - $(window).height();
+
   updateScrollVars();
});
});
Line 68: Line 68:
});
});
-
var wheel = false,
+
var wheel = false, $docH, $scrollTop;
-
$docH = $(document).outerHeight() - $(window).height(),
+
 
-
$scrollTop = $(document).scrollTop();
+
function updateScrollVars(){
 +
  $docH = $(document).outerHeight() - $(window).height(),
 +
  $scrollTop = $(document).scrollTop();
 +
}
 +
 
$(window).bind('scroll', function() {
$(window).bind('scroll', function() {
-
  if (wheel === false) {
+
    if (wheel === false) {
-
    $scrollTop = $(document).scrollTop();
+
        $scrollTop = $(this).scrollTop();
-
  }
+
    }
});
});
$(document).bind('DOMMouseScroll mousewheel', function(e, delta) {
$(document).bind('DOMMouseScroll mousewheel', function(e, delta) {
-
  delta = delta || -e.originalEvent.detail / 3 || e.originalEvent.wheelDelta / 60;
+
    delta = delta || -e.originalEvent.detail / 3 || e.originalEvent.wheelDelta / 120;
-
  wheel = true;
+
    wheel = true;
-
  $scrollTop = Math.min($docH, Math.max(0, parseInt($scrollTop - delta * 30)));
+
    $scrollTop = Math.min($docH, Math.max(0, parseInt($scrollTop - delta * 30)));
-
  console.log($scrollTop);
+
    $($.browser.webkit ? 'body' : 'html').stop().animate({
-
  $(true ? 'body' : 'html').stop().animate({
+
        scrollTop: $scrollTop + 'px'
-
    scrollTop: $scrollTop + 'px'
+
    }, 2000, 'easeOutQuint', function() {
-
  }, 2000, 'easeOutQuint', function() {
+
        wheel = false;
-
    wheel = false;
+
    });
-
  });
+
    return false;
-
  return false;
+
});
});

Revision as of 22:09, 25 September 2014

recalcRingSize = function(setPosition) {

 var placeholder = $("#img-placeholder");
 var ring = $("#ring");
 var width = placeholder.outerWidth(false);
 var position = placeholder.offset();
 position.left = position.left - $(".container").offset().left;
 if(setPosition){
   ring.css(position);
 }
 ring.css("width", width+"px");
 placeholder.css("height", ring.height()+"px");

};


function setTweenParams(tween) {

 var params = {css: {
   left: $('#ring').width()/-2,
   top: $('.second').position().top + ($('.second').outerHeight() - $('#ring').height())/2
 }};
 tween.updateTo(params, false);

}

var moveRing = new TweenMax("#ring", 2, {}); var scene = new ScrollScene({duration: 1000}); var timeline = new TimelineMax();

$(document).ready(function(){

 controller = new ScrollMagic();
 timeline.add(moveRing, 0);
 $("#ring").load(function(){
   recalcRingSize(true);
   $("#img-placeholder img").css("display", "none");
   $("#ring").css("visibility", "");
   setTweenParams(moveRing);
   timeline.to("#ring", 4, { rotation: 360}, 0);
   scene.setTween(timeline);
 });


 scene
   .setTween(timeline)
   .addTo(controller);
 scene2 = new ScrollScene({duration: 10});
 scene2.setTween(TweenMax.to("#front-nav ul", 2, { padding: "10px 20px"})).addTo(controller);
 //scene.addIndicators();
 $("#front-nav ul li a").tooltip()
 $("#front-nav ul li a").mouseenter(function(){$(this).find('img').animate({opacity: 0}, 200);});
 $("#front-nav ul li a").mouseleave(function(){
   $(this).find('img').stop(true, true);
   $(this).find('img').css("opacity", 1);
 });

});

$( window ).resize(function() {

 recalcRingSize(false);
 setTweenParams(moveRing);
 scene.setTween(timeline);
 updateScrollVars();

});


jQuery.extend(jQuery.easing, {

 easeOutQuint: function(x, t, b, c, d) {
   return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
 }

});

var wheel = false, $docH, $scrollTop;

function updateScrollVars(){

 $docH = $(document).outerHeight() - $(window).height(),
 $scrollTop = $(document).scrollTop();

}


$(window).bind('scroll', function() {

   if (wheel === false) {
       $scrollTop = $(this).scrollTop();
   }

});

$(document).bind('DOMMouseScroll mousewheel', function(e, delta) {

   delta = delta || -e.originalEvent.detail / 3 || e.originalEvent.wheelDelta / 120;
   wheel = true;
   $scrollTop = Math.min($docH, Math.max(0, parseInt($scrollTop - delta * 30)));
   $($.browser.webkit ? 'body' : 'html').stop().animate({
       scrollTop: $scrollTop + 'px'
   }, 2000, 'easeOutQuint', function() {
       wheel = false;
   });
   return false;

});