jquery - 如何判断页面是否一直滚动到一边
问题描述
我有一个溢出视口的页面。用户可以滚动或滑动查看整个页面。我想根据用户滚动的距离将消息从“向右滑动”更改为“向左滑动”,但我遇到了麻烦。我怎么知道我什么时候横向滚动到最后?任何人都可以帮忙吗?
var totalWidth = $('.container').width();
$(window).scroll(function() {
var documentScrollLeft = $(document).scrollLeft();
//switch command to swipe left or right depending on what point the user has scrolled to
if (documentScrollLeft >= width) {
$('.swipe').html("<i class='fas fa-arrow-left'></i> SWIPE LEFT");
} else {
$('.swipe').html("SWIPE RIGHT <i class='fas fa-arrow-right'></i>");
}
});
.container {
display: flex;
/*align-items: center;*/
/*width: 100%;*/
position: absolute;
top: 0;
left: 0;
/*height:100vh;*/
margin-top: 0px;
}
@media only screen and (max-width: 1024px) {
.container {
top: 32px;
}
}
.panel {
height: 100vh;
/*width: 25%;*/
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="swipe mobile">SWIPE RIGHT <i class="fas fa-arrow-right"></i></div>
<div class='container'>
<img name="panel1" src="img/panel1.jpg" border="0" id="" alt="" class="panel" />
<img name="panel2" src="img/panel2.jpg" border="0" id="" alt="" class="panel" />
<img name="panel3" src="img/panel3.jpg" border="0" id="" alt="" class="panel" />
<img name="panel4" src="img/panel4.jpg" border="0" id="" alt="" class="panel" />
</div>
解决方案
这是你的起点,只需要设置你的逻辑。
var lastScrollLeft = 0;
$(window).scroll(function() {
var documentScrollLeft = $(document).scrollLeft();
if (lastScrollLeft != documentScrollLeft) {
console.log('horizontal scroll x');
lastScrollLeft = documentScrollLeft;
}
});
推荐阅读
- rest - 无法对 github 存储库统计信息进行分页
- spring - @ControllerAdvice 未捕获 Rest API 异常
- php - php - fpdf 选择案例 $row
- ios - 架构 arm64 的 1188 个重复符号
- blazor - 检测客户端关闭连接 Blazor
- python - 将字符串拆分到第 n 次出现的分隔符
- bash - 仅移动样本表中命名为特定行的那些文件
- python - 比较句子列表和单词列表,如果单词存在,则返回完整的句子
- angular - 如何制作三个状态的复选框
- typescript - Why import assignment makes module declaration with a relative module name valid?