[英]how to scroll to bottom of a div
我想滚动到div content-main
的底部,以便将Button
显示在bottom of the window
的bottom of the window
。 我尝试了以下方法:
<div class="container">
<div class="content-main">
dynamic content dynamic content.....
<button>Button </button>
</div>
<div class ="footer"></div>
</div>
<script>
var mainContentHeight = $(".content-main").height();
var footerHeight = $(".content-footer").height();
window.scrollTo(0, mainContentHeight - footerHeight);
</script>
当我在具有不同尺寸的两台显示器中对其进行测试时,其工作原理有所不同。 如何在窗口底部显示按钮?
而是将scrollTo绑定到window对象,将其绑定到要滚动的元素:
var container = $('.container')[0]; var contentMain = $('.content-main')[0]; var mainContentHeight = $(".content-main").height(); var footerHeight = $(".content-footer").height(); container.scrollTo(0, mainContentHeight - footerHeight);
.container { overflow: auto; height: 100px; } .content-main { height: 100%; position: relative; border: 1px solid #000; height: 1000px; } .content-footer { height: 50px; } button { position: absolute; bottom: 0; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="container"> <div class="content-main"> dynamic content dynamic content..... <button>Button </button> </div> <div class="content-footer"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.