JQuery scroll button used to scroll the page 100%

I am building a website and have problems with a button that uses jQuery to scroll down the page 100%. I have problems because it scrolls different spaces between browsers and window sizes. Any solution to my problem? By the way, here is my code ...

JQuery

var screenheight100 = css('height', '100%');
$('#gdb1').click(function(){
    $("html, body").animate({ scrollTop: (screenheight100)}, 600);
    return false;
 });

HTML

<div class="gdbox"><div id="gdb1" class="gdbutton fontwhitenshadow">Q</div></div>

CSS

.gdbox{width: 100%;
       height: 35px;
       position: absolute;
       bottom: 30px; 
       text-align: center;
       overflow: visible;
}
.gdbutton{margin: 0 auto;
          height: 20px;
          padding-bottom: 20px;
          text-align: center;
          width: 40px;
          font-family: iconFont;
          font-size: 45px;
          cursor: pointer;
}
+4
source share
2 answers

I assume that you want to achieve the scrolling of the window as the height of the window.

But css()it is not a global function, it is a jQuery object method.

you can get the height of the window using the method .height():

$('#gdb1').click(function(){
    $("html, body").animate({ scrollTop: $(window).height()}, 600);
    return false;
});

Working script

, $(selector).offset().top.

+10

. .

0

All Articles