Team:UCLA/Template/Javascript

From 2014.igem.org

(Difference between revisions)
Line 109: Line 109:
</script>
</script>
-
<!--STICKY SIDEBAR-->
+
<!--BACK TO TOP BUTTON-->
 +
//Back-To-Top Button
 +
//==================
 +
$(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');
 +
};
 +
 
 +
//Smooth Anchor Scrolling
 +
//=======================
 +
$(".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');
 +
});
 +
 
</html>
</html>

Revision as of 00:06, 5 August 2014

//Back-To-Top Button //================== $(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'); }; //Smooth Anchor Scrolling //======================= $(".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'); });