Skip to content

Instantly share code, notes, and snippets.

@SOLUNTECH
Created March 13, 2015 18:31
Show Gist options
  • Save SOLUNTECH/fab6e30f16e86e9b7e34 to your computer and use it in GitHub Desktop.
Save SOLUNTECH/fab6e30f16e86e9b7e34 to your computer and use it in GitHub Desktop.

Revisions

  1. Soluntech created this gist Mar 13, 2015.
    16 changes: 16 additions & 0 deletions document.scroll.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    $(document).scroll( function(){
    var headerOffset = 0;
    var scrollPos = $(document).scrollTop();
    var ancho = $( window ).width();

    if(ancho > 768){ headerOffset = 100; }
    else{ headerOffset = 80; }

    if (scrollPos > headerOffset){
    $('.navbar > .container .navbar-collapse ul, .navbar>.container .navbar-brand').addClass('collapsed');
    $('#topnav').fadeIn();
    } else {
    $('.navbar > .container .navbar-collapse ul, .navbar>.container .navbar-brand').removeClass('collapsed');
    $('#topnav').fadeOut();
    }
    });
    38 changes: 38 additions & 0 deletions scrolls.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    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);
    });
    }