Javascript jquery/css-检测错误<;部门>';让我们向下滚动
在这里,我制作了一个带有向下滚动按钮的可滚动Javascript jquery/css-检测错误<;部门>';让我们向下滚动,javascript,html,jquery,css,Javascript,Html,Jquery,Css,在这里,我制作了一个带有向下滚动按钮的可滚动,当到达底部时,该按钮将消失 <h1>header</h1> <hr> <div style="position: relative; height:75%"> <div class="utt" style="overflow: auto; height:100%"> <p>a</p><p>a<
,当
到达底部时,该按钮将消失
<h1>header</h1>
<hr>
<div style="position: relative; height:75%">
<div class="utt" style="overflow: auto; height:100%">
<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>
</div>
<center><a id="appear" class="toBottom" onclick="scroll" style="position: absolute; bottom: 40px; right: 40px; border-radius: 5px;"><button style="border-radius: 3px"><b>scroll<br>down</b></button></a></center>
</div>
<hr>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function scroll() {
$(".toBottom").click(function scroll() {
let elm = $(".utt")
elm.animate({
scrollTop: elm[0].scrollHeight
}, 500);
});
});
$(".utt").scroll(function() {
if($(this).scrollTop() + $(this).innerHeight() > $(this)[0].scrollHeight) {
$(".toBottom").hide(120);
} else {
$(".toBottom").show(120);
}
});
</script>
标题
aaaaaaa
aaaaaaa
aa
向下滚动
$(文档).ready(函数滚动(){
$(“.toBottom”)。单击(函数滚动(){
设elm=$(“.utt”)
榆树({
scrollTop:elm[0]。scrollHeight
}, 500);
});
});
$(“.utt”).scroll(函数(){
如果($(此).scrollTop()+$(此).innerHeight()>$(此)[0].scrollHeight){
$(“.toBottom”).hide(120);
}否则{
$(“.toBottom”).show(120);
}
});
现在这里有一个错误:使按钮消失的功能在某些屏幕分辨率下有效,而在其他屏幕分辨率下无效。例如,它可以在全尺寸桌面浏览器中工作,但不能在移动浏览器或最小化(更小)桌面浏览器中工作。如何在所有情况下都能做到这一点?使用您粘贴的代码,元素
utt
根本不滚动,滚动发生在主体中。您需要给utt
一个固定的高度,滚动条才会出现,或者将jqueryscroll
功能应用到$(窗口)
:
标题
aaaaaaa
aaaaaaa
aa
向下滚动
$(文档).ready(函数(){
$(“.toBottom”)。单击(函数滚动(){
设elm=$(“.utt”)
榆树({
scrollTop:elm[0]。scrollHeight
}, 500);
});
$(“.utt”).scroll(函数(){
如果($(此).scrollTop()+$(此).innerHeight()>=$(此)[0].scrollHeight){
$(“.toBottom”).hide(120);
}否则{
$(“.toBottom”).show(120);
}
});
});
使用粘贴的代码,元素utt
根本不滚动,滚动发生在主体中。您需要给utt
一个固定的高度,滚动条才会出现,或者将jqueryscroll
功能应用到$(窗口)
:
标题
aaaaaaa
aaaaaaa
aa
向下滚动
$(文档).ready(函数(){
$(“.toBottom”)。单击(函数滚动(){
设elm=$(“.utt”)
榆树({
scrollTop:elm[0]。scrollHeight
}, 500);
});
$(“.utt”).scroll(函数(){
如果($(此).scrollTop()+$(此).innerHeight()>=$(此)[0].scrollHeight){
$(“.toBottom”).hide(120);
}否则{
$(“.toBottom”).show(120);
}
});
});