我制作了一个带有浮动按钮的滚动条,单击该滚动条可以使其滚动到底部,
<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>
当按钮完全滚动到底部时,如何使此按钮消失?
答案 0 :(得分:1)
添加此html:
<button id="scrollDown" onclick="bottom()">Scroll to bottom</button>
然后将其添加到Javascript:
var mybutton = document.getElementById("scrollDown");
window.onscroll = function() {scrollFunction()};
function scrollFunction() {
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;
}