javascript - Detecting by how much user has scrolled -


i have image pop-up ability on website, in order show users full resolution picture when click on smaller version on page.

this current css positions it:

div#enlargedimgwrapper { position: absolute; top: 30px; left: 55px; z-index: 999; } 

the problem if click on image further down page, window still appears in top left corner of page, can't see until scroll up. need appear relative window, whatever current position relative document is.

note: don't want use position: fixed; images might taller screen, want users able scroll along image well.

my idea use js change top value:

var scrollvalue = ???; document.getelementbyid('enlargedimgwrapper').style.top = scrollvalue+30 + 'px'; 

how can detect how user has scrolled down page (var scrollvalue)?
or there 'better' way this?

edit: if possible without jquery.

pure javascript uses scrolltop , scrollleft:

var scrollleft = (window.pagexoffset !== undefined) ? window.pagexoffset : (document.documentelement || document.body.parentnode || document.body).scrollleft; var scrolltop = (window.pageyoffset !== undefined) ? window.pageyoffset : (document.documentelement || document.body.parentnode || document.body).scrolltop; 

https://developer.mozilla.org/en-us/docs/web/api/element.scrolltop

jquery version:

var scrollleft = $(window).scrollleft() ; var scrolltop = $(window).scrolltop() ; 

what need this:

document.getelementbyid('enlargedimgwrapper').style.top = (scrolltop+30) + 'px'; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -