Team:UCLA/Template/Javascript

From 2014.igem.org

(Difference between revisions)
Line 110: Line 110:
<!--BACK TO TOP BUTTON-->
<!--BACK TO TOP BUTTON-->
-
//Back-To-Top Button
 
-
//==================
 
$(function(){
$(function(){
$(document).on( 'scroll', function(){
$(document).on( 'scroll', function(){
Line 131: Line 129:
};
};
-
//Smooth Anchor Scrolling
+
 
-
//=======================
+
  $(".scroll").click(function(event){
  $(".scroll").click(function(event){
event.preventDefault();
event.preventDefault();

Revision as of 00:07, 5 August 2014

$(function(){ $(document).on( 'scroll', function(){ if ($(window).scrollTop() > 100) { $('.scroll-top-wrapper').addClass('show'); } else { $('.scroll-top-wrapper').removeClass('show'); } }); $('.scroll-top-wrapper').on('click', scrollToTop); }); function scrollToTop() { verticalOffset = typeof(verticalOffset) != 'undefined' ? verticalOffset : 0; element = $('body'); offset = element.offset(); offsetTop = offset.top; $('html, body').animate({scrollTop: offsetTop},700, 'swing'); }; $(".scroll").click(function(event){ event.preventDefault(); //calculate destination place var dest=0; if($(this.hash).offset().top > $(document).height()-$(window).height()){ dest=$(document).height()-$(window).height(); }else{ dest=$(this.hash).offset().top; } //go to destination $('html,body').animate({scrollTop:dest}, 700,'swing'); });