html - Javascript: target specific div or element? -



html - Javascript: target specific div or element? -

i want rewrite next code doesn't height of <body>, rather height of element set object in carry out function:

var img = document.getelementbyid("logo"); window.onscroll = function() { var bodyheight = parseint(getcomputedstyle(document.body).height, 10); var scrolllimit = bodyheight - window.innerheight; var scrolltop = document.body.scrolltop; var scrollpct = (scrolltop / (scrolllimit / 100)) / 100; logo.style.top = bodyheight * scrollpct - logo.offsetheight + "px"; };

how can target, id, instead of document.body? tried next didn't work @ all:

var img = document.getelementbyid("logo"); window.onscroll = function() { var body = document.getelementbyid("container"); var bodyheight = parseint(getcomputedstyle(document.getelementbyid("container")).height, 10); var scrolllimit = bodyheight - window.innerheight; var scrolltop = document.getelementbyid("container").scrolltop; var scrollpct = (scrolltop / (scrolllimit / 100)) / 100; logo.style.top = bodyheight * scrollpct - logo.offsetheight + "px"; };

the desired effect involves reverse scroll in image move downwards user scrolls down, instead of up, does.

i guess computed height not work? utilize clientheight property:

var bodyheight = document.getelementbyid("container").clientheight;

(or 1 of other height properties)

javascript html scroll target

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -