- This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
Viewing 3 posts - 1 through 3 (of 3 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › www.microsoft.com/ceo scroll effect
Hi,
On http://www.microsoft.com/ceo there are blue markers on the right hand side of the screen that show the readers position on the page.
Is there a simple preferably jQuery way to achieve this?
Thanks
The core components of that effect are
$(window).height()
] // simple with jQuery, a little more of a pain in vanilla JSbody.scrollTop()
]elem.offset().top
, elem.outerHeight(true)
]Really basic example : http://codepen.io/shawkdsn/pen/rLIgC
This excerpt makes the navigation dots dynamically. There’s a lot more one could do to generalize and encapsulate this into a reusable plugin, but why reinvent the wheel? https://github.com/imakewebthings/jquery-waypoints
Cheers
Thought I should add this nice bit of code. Source: http://blog.adtile.me/2014/01/16/a-dive-into-plain-javascript/
// Determine if an element is in the visible viewport
function isInViewport(element) {
var rect = element.getBoundingClientRect();
var html = document.documentElement;
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || html.clientHeight) &&
rect.right <= (window.innerWidth || html.clientWidth)
);
}
The above function could be used by adding a “scroll” event listener to the window and then calling isInViewport().