javascript - Page scroll to the bottom of a div -
how align bottom of div bottom of page on button click? similar using window.location.href = '#div1'
align screen top of 'div1
'
<html> <head> </head> <body> <div id="div1" style="border: 1px solid #cccccc; position: absolute; background: #fa8258" onclick="window.location.href='#div2'"> div orange. click see div yellow. </div> <div id="div2" style="border: 1px solid #cccccc; position: absolute; top: 800px; background: #f4fa58" onclick="window.location.href='#div3'"> div yellow. click see div blue. want div @ bottom instead of top on click of div orange. </div> <div id="div3" style="border: 1px solid #cccccc; position: absolute; top: 1600px; background: #a9f5e1;" onclick="window.location.href='#div1'"> div blue. click see div orange. </div> </body> </html>
i think job you. assuming wanting scroll in body. $(window).height()
refers viewport height.
function jumpbottom(from, id) { var = document.getelementbyid(id); document.body.scrolltop = to.offsettop - $(window).height() + to.offsetheight; }
<div id="div1" style="border: 1px solid #cccccc; position: absolute; background: #fa8258" onclick="jumpbottom(this,'div2')"> div orange. click see div yellow. </div> <div id="div2" style="border: 1px solid #cccccc; position: absolute; top: 800px; background: #f4fa58" onclick="window.location.href='#div3'"> div yellow. click see div blue. want div @ bottom instead of top on click of div orange. </div> <div id="div3" style="border: 1px solid #cccccc; position: absolute; top: 1600px; background: #a9f5e1;" onclick="window.location.href='#div1'"> div blue. click see div orange. </div>
Comments
Post a Comment