Team:Toronto/scripts/main
From 2014.igem.org
// Canvas var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d'), cx, cy; var cw = canvas.width = $('html').width(); var ch = canvas.height = $('html').height(); // Some variables var d = 35; var x = Math.random() * (cw - d), y = Math.random() * (ch - d); var speedX = 5, speedY = 5; var directionX = 1, directionY = 1;
/*var topDist; var scroll;*/
$(document).ready(function() { main(); });
function main(){ resizeCanvas(); window.addEventListener('resize', resizeCanvas, false);
$(document).scroll(function () {
scroll = $(this).scrollTop(); if (scroll >= topDist.top) { $('nav').removeClass('free'); $('nav').addClass('stuck'); //console.log("Changed to stuck!"); //$('#main').height($('html').height() - $navHeight); } else if (scroll < topDist.top){ $('nav').removeClass('stuck'); $('nav').addClass('free'); //console.log('not stuck'); } }); $('#navbar li').click(function(){ console.log('1 ' + $(window).scrollTop()); $(window).scrollTop(topDist.top); console.log('2 ' + $(window).scrollTop()); $('#main-inner').css({'top':'0'}); //$('window').scrollTop(topDist.top); });
}
function resizeCanvas() { cw = canvas.width = $('html').width(); ch = canvas.height = $('html').height(); cx = cw / 2; cy = ch / 2; resizeRelativeToWindow('#splash-wrapper', $navHeight); topDist = $("nav").offset(); console.log(topDist); }
function resizeRelativeToWindow(element, bottomMargin) { $(element).height($('html').height() - $navHeight + $navBorder); $('#splash').height($(element).height());
// This prevents FF from showing scrollbar when not necessary if($('#splash .container').height() > $(element).height() ){ $('#splash').css({ 'overflow-y': 'scroll' }); } else { $('#splash').css({ 'overflow-y': 'hidden' }); } }