Last active
May 11, 2016 00:32
-
-
Save fxcosta/9b5fe73a183b68171f15 to your computer and use it in GitHub Desktop.
A simple scrolling that works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <![CDATA[ | |
$(document).ready(function() { | |
function filterPath(string) { | |
return string | |
.replace(/^\//,'') | |
.replace(/(index|default).[a-zA-Z]{3,4}$/,'') | |
.replace(/\/$/,''); | |
} | |
$('a[href*=#]').each(function() { | |
if ( filterPath(location.pathname) == filterPath(this.pathname) | |
&& location.hostname == this.hostname | |
&& this.hash.replace(/#/,'') ) { | |
var $targetId = $(this.hash), $targetAnchor = $('[name=' + this.hash.slice(1) +']'); | |
var $target = $targetId.length ? $targetId : $targetAnchor.length ? $targetAnchor : false; | |
if ($target) { | |
var targetOffset = $target.offset().top; | |
$(this).click(function() { | |
$('html, body').animate({scrollTop: targetOffset - 170}, 850); | |
return false; | |
}); | |
} | |
} | |
}); | |
// Muda o bg do header com o scroll | |
/* jQuery(window).scroll(function(){ | |
var fromTopPx = 50; // distance to trigger | |
var scrolledFromtop = jQuery(window).scrollTop(); | |
if(scrolledFromtop > fromTopPx){ | |
$('#header').css('background-image','none'); | |
}else{ | |
$('#header').css('background-image','url(/templates/sTemplate/images/Bg_Menu.png)'); | |
} | |
});*/ | |
}); | |
// ]]> | |
(function($) { | |
$(document).ready(function($) { | |
$(function() { | |
$('a[href*=#]:not(.carousel-control)').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { | |
var target = $(this.hash); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
$('html, body').animate({ | |
scrollTop: target.offset().top - 100 | |
}, 1000); | |
return false; | |
} | |
} | |
}); | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment