Skip to content

Instantly share code, notes, and snippets.

@PetraMotz
Last active August 4, 2021 11:26
Show Gist options
  • Save PetraMotz/81f448b990677215c8f848aa00f13ced to your computer and use it in GitHub Desktop.
Save PetraMotz/81f448b990677215c8f848aa00f13ced to your computer and use it in GitHub Desktop.
JQuery Scroll #js #scroll
function onScrollActivateSectionAnchor(){
var scrollTop = $(window).scrollTop();
var header= $('#header').offset().top;
var headerHight = $('#header').height();
var headerHalf = (headerHight/2)-70;
$('.scrollAnchor').each(function(){
var distance= $(this).offset().top - scrollTop;
var height= $(this).height();
var quarter = height/4;
var half = height/2;
var threeQuarter = quarter*3;
var filter = $(this).attr('data-filter');
if(header - scrollTop <= -headerHalf){
$('.sideSection.first').addClass('mid');
}
else{
$('.sideSection.first').removeClass('mid');
}
if(header - scrollTop <= -headerHight){
$('.sideSection.first').addClass('full');
}
else{
$('.sideSection.first').removeClass('full');
}
if(distance <= 70){
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).addClass('passed');
}
});
}
else{
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).removeClass('passed');
}
});
}
if(distance <= -quarter){
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).addClass('quarter').removeClass('mid').removeClass('.threeQuarter').removeClass('full');
}
});
}
else{
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).removeClass('quarter').removeClass('mid').removeClass('threeQuarter').removeClass('full');
}
});
}
if(distance <= -half){
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).addClass('mid').removeClass('quarter').removeClass('.threeQuarter').removeClass('full');
}
});
}
else{
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).removeClass('mid').removeClass('threeQuarter').removeClass('full');
}
});
}
if(distance <= -threeQuarter){
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).addClass('threeQuarter').removeClass('quarter').removeClass('.mid').removeClass('full');
}
});
}
else{
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).removeClass('threeQuarter').removeClass('full');
}
});
}
if(distance <= -height){
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).addClass('full').removeClass('quarter').removeClass('.mid').removeClass('threeQuarter');
}
});
}
else{
$('.sideSection').each(function(){
if($(this).attr('data-filter') == filter){
$(this).removeClass('full');
}
});
}
})
};
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > 250) {
jQuery('#topwrap').fadeIn();
clearTimeout(jQuery.data(this, 'scrollTimer'));
jQuery.data(this, 'scrollTimer', setTimeout(function() {
jQuery('#topwrap').fadeOut();
}, 1000));
} else {
jQuery('#topwrap').fadeOut();
}
});
jQuery('#linktotop').click(function() {
jQuery("html, body").animate({
scrollTop: 0
}, 600);
return false;
});
$('html,body').animate({
scrollTop: $(this).offset().top - 80
},'slow');
$('html, body').animate({
scrollTop: $(".error").offset().top - 200
}, 200);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment