Skip to content

Instantly share code, notes, and snippets.

@SOLUNTECH
Created March 13, 2015 18:30
Show Gist options
  • Save SOLUNTECH/4cca0c73f7ffbe2c7d8b to your computer and use it in GitHub Desktop.
Save SOLUNTECH/4cca0c73f7ffbe2c7d8b to your computer and use it in GitHub Desktop.
function scrolls(){
$('body').on('click', '.link_to', function(e){
e.preventDefault();
var id = $(this).attr('href');
var scroll = $(id).offset().top - 50;
if(id == "#home"){ scroll = 0; }
if($( window ).width() > 768){
if(id == "#apps" || id == "#contact"){
scroll -= 5;
}
}else{
if(id != "#home"){
scroll -= 20;
}
}
if(id != "#home"){ $('.navbar-default .navbar-toggle').click(); }
var media = $("body").height();
var maxTime = 2000;
var offset = $(id).offset().top;
console.log(offset)
var time = (offset * maxTime) / media;
console.log(time, 'time');
$('html, body').animate({
scrollTop: scroll
}, time);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment