Created
September 24, 2015 09:00
-
-
Save madalinignisca/abce2f25de1f2ae57540 to your computer and use it in GitHub Desktop.
Get position on window scroll
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
/* This is a snippet found on stackoverflow: http://stackoverflow.com/questions/3714628/jquery-get-the-location-of-an-element-relative-to-window | |
*/ | |
function log(txt) { | |
$("#log").html("location : <b>" + txt + "</b> px") | |
} | |
$(function() { | |
var eTop = $('#element').offset().top; //get the offset top of the element | |
log(eTop - $(window).scrollTop()); //position of the ele w.r.t window | |
$(window).scroll(function() { //when window is scrolled | |
log(eTop - $(window).scrollTop()); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment