[英]How to make scroll button disappear when scrolled to bottom
我制作了一個帶有浮動按鈕的滾動條,單擊時它會滾動到底部,
<style>
box {
padding: 8px 20px;
border: 1px solid #222;
position: sticky;
bottom:10px;
left:30px;
box-shadow: -3px 3px 3px #999;
}
</style>
<hr>
<div id="utt" style="overflow-y: scroll; height:75%;">
<p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p><p>a</p>
<a href="#" onclick="scroll" class="toBotetom"><box><b>Scroll to bottom</b></box></a>
</div>
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function scroll() {
$("a.toBotetom").click(function scroll() {
let elm = $("#utt")
elm.animate({
scrollTop: elm[0].scrollHeight
}, 500);
});
});
</script>
完全滾動到底部時,如何使此按鈕消失?
<button id="scrollDown" onclick="bottom()">Scroll to bottom</button>
然后將其添加到 Javascript:
var mybutton = document.getElementById("scrollDown");
window.onscroll = function() {scrollFunction()};
function bottom() {
if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
mybutton.style.display = "block";
} else {
mybutton.style.display = "none";
}
}
// When the user clicks on the button, scroll to the bottom of the document
function bottom() {
document.body.scrollTop = 0;
document.documentElement.scrollTop = 5555550;
}
現在對於 CSS:
#scrollDown {
display: none;
position: fixed;
bottom: 20px;
right: 30px;
z-index: 99;
font-size: 18px;
border: none;
outline: none;
background-color: red;
color: white;
cursor: pointer;
padding: 15px;
border-radius: 4px;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.