Created
November 25, 2014 04:22
-
-
Save muskie9/ded280e348176bdd8148 to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* This demo was prepared for you by Petr Tichy - Ihatetomatoes.net | |
* Want to see more similar demos and tutorials? | |
* Help by spreading the word about Ihatetomatoes blog. | |
* Facebook - https://www.facebook.com/ihatetomatoesblog | |
* Twitter - https://twitter.com/ihatetomatoes | |
* Google+ - https://plus.google.com/u/0/109859280204979591787/about | |
* Article URL: http://ihatetomatoes.net/simple-parallax-scrolling-tutorial/ | |
*/ | |
( function( $ ) { | |
// Setup variables | |
$window = $(window); | |
$slide = $('.homeSlide'); | |
$body = $('body'); | |
$section = $('section'); | |
//FadeIn all sections | |
$body.imagesLoaded( function() { | |
setTimeout(function() { | |
// Resize sections | |
if ($(window).width() > 800) { | |
adjustWindow(); | |
} else { | |
// $('section').css("height", $window.height()); | |
skrollr.init().destroy(); // skrollr.init() returns the singleton created above | |
} | |
// Fade in sections | |
$body.removeClass('loading').addClass('loaded'); | |
}, 800); | |
}); | |
$(window).on('resize', function () { | |
if ($(window).width() <= 768) { | |
skrollr.init().destroy(); // skrollr.init() returns the singleton created above | |
} else { | |
skrollr.init(); | |
adjustWindow(); | |
} | |
}); | |
function adjustWindow(){ | |
// Init Skrollr | |
// Get window size | |
winH = $window.height(); | |
// Keep minimum height 550 | |
if(winH <= 720) { | |
winH = 720; | |
} | |
// Resize our slides | |
$slide.height(winH); | |
// Init Skrollr | |
var s = skrollr.init({ | |
forceHeight: false | |
}); | |
// Refresh Skrollr after resizing our sections | |
s.refresh($('.homeSlide')); | |
} | |
$('.slide-1').click(function(e){ | |
e.preventDefault(); | |
$.scrollTo( '#slide-1' , 1000 ); | |
}); | |
$('.slide-2').click(function(e){ | |
e.preventDefault(); | |
$.scrollTo( '#slide-2' , 1000 ); | |
}); | |
$('.slide-3').click(function(e){ | |
e.preventDefault(); | |
$.scrollTo( '#slide-4' , 1000 ); | |
}); | |
$('.slide-4').click(function(e){ | |
e.preventDefault(); | |
$.scrollTo( '#slide-6' , 1000 ); | |
}); | |
// $(window).scroll(function(){ | |
// if ($(window).scrollTop() > 70){ | |
// $(".navigation").addClass("mod-header-fixed"); | |
// } else if ($(window).scrollTop() < 70) { | |
// $(".navigation").removeClass("mod-header-fixed"); | |
// } | |
// }); | |
var winHeight, adjustedHeight | |
function setWidth(){ | |
winHeight = $(window).height(); | |
adjustedHeight = winHeight - 75; | |
} | |
setWidth(); | |
$(window).resize(setWidth()); | |
$(window).on('resize', function () { | |
var winHeight = $(window).height(); | |
var adjustedHeight = winHeight - 75; | |
}); | |
$(document).ready(function(){ | |
if (winHeight < 720) { | |
$('#menu').addClass("heightAdjust"); | |
// console.log(winHeight); | |
} | |
}) | |
$(window).scroll(function(){ | |
if ($(window).scrollTop() > adjustedHeight){ | |
$("#menu").addClass("mod-header-fixed"); | |
} else if ($(window).scrollTop() < adjustedHeight) { | |
$("#menu").css("bottom", $(window).scrollTop()); | |
$("#menu").removeClass("mod-header-fixed"); | |
} | |
var distance = $('#slide-2').offset().top - 75, | |
distance2 = $('#slide-4').offset().top - 75, | |
distance3 = $('#slide-6').offset().top - 75, | |
distance4 = $('#slide-1').offset().top, | |
$window = $(window); | |
if ( $window.scrollTop() >= distance ) { | |
$('#menu ul li').removeClass("active"); | |
$('#menu ul li.slide-2').addClass("active"); | |
} | |
if ( $window.scrollTop() >= distance2 ) { | |
$('#menu ul li').removeClass("active"); | |
$('#menu ul li.slide-3').addClass("active"); | |
} | |
if ( $window.scrollTop() >= distance3 ) { | |
$('#menu ul li').removeClass("active"); | |
$('#menu ul li.slide-4').addClass("active"); | |
} | |
if ( $window.scrollTop() < winHeight ) { | |
$('#menu ul li').removeClass("active"); | |
$('#menu ul li.slide-1').addClass("active"); | |
} | |
}); | |
} )( jQuery ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment