So I'm attempting to grasp the beginning of how to get a function working beyond just seeing plugins do what I ask. For example this plugin does a "jump to" upon clicking those div links in the nav. What I'd like is when you get to a certain part of a div it jumps to the rest of the div. Thereby cutting out the nav bar entirely but utilizing the easing to reach the rest of the article/photo, etc.
Currently I'm using a script for parallax by Richard Shepard and I'd like to expand the script to use the backgroundPosition: coordinates to trigger a scroll to event.
I've pasted in his code for convenience.
P.S. All this code is working as it "should" yet, it is lacking an easing between divs, and currently I have on my install jquery.easing .
P.P.S. Yet, I'm not sure where I need to start. So, I figured start with the functions that are getting the users location on the page already.
// On your marks, get set...
$(document).ready(function(){
console.log("loaded parallax");
// Cache the Window object
$window = $(window);
// Cache the Y offset and the speed of each sprite
$('[data-type]').each(function() {
$(this).data('offsetY', parseInt($(this).attr('data-offsetY')));
$(this).data('Xposition', $(this).attr('data-Xposition'));
$(this).data('speed', $(this).attr('data-speed'));
});
// For each element that has a data-type attribute
$('section[data-type="background"]').each(function(){
// Store some variables based on where we are
var $self = $(this),
offsetCoords = $self.offset(),
topOffset = offsetCoords.top;
// When the window is scrolled...
$(window).scroll(function() {
// If this section is in view
if ( ($window.scrollTop() + $window.height()) > (topOffset) &&
( (topOffset + $self.height()) > $window.scrollTop() ) ) {
// console.log("scrolling background");
// Scroll the background at var speed
// the yPos is a negative value because we're scrolling it UP!
var yPos = -($window.scrollTop() / $self.data('speed'));
// If this element has a Y offset then add it on
if ($self.data('offsetY')) {
yPos += $self.data('offsetY');
}
// Put together our final background position
var coords = '50% '+ yPos + 'px';
// Move the background
$self.css({ backgroundPosition: coords });
// Check for other sprites in this section
$('[data-type="sprite"]', $self).each(function() {
// Cache the sprite
var $sprite = $(this);
// Use the same calculation to work out how far to scroll the sprite
var yPos = -($window.scrollTop() / $sprite.data('speed'));
var coords = $sprite.data('Xposition') + ' ' + (yPos + $sprite.data('offsetY')) + 'px';
$sprite.css({ backgroundPosition: coords });
}); // sprites
}; // in view
}); // window scroll
}); // each data-type
}); // document ready
here is the beginning of my code within the // If this section is in view section:
var windowheight = jQuery(window).height();
// console.log(yPos);
if (Math.abs(yPos) > windowheight/2) {
console.log("scrollto");
jQuery('#fourth').ScrollTo();
}