当div滚动到时运行javascript函数 [英] Run javascript function when div is scrolled to

查看:75
本文介绍了当div滚动到时运行javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户滚动到div使其可见时,如何运行onclick函数.尝试设置自动加载的无限滚动,而不是用户单击此按钮.

How do I run the onclick function when the div becomes visible by the user scrolling to it. Trying to set up infinite scrolling that loads automatically instead of users clicking this button.

元素在另一个div内水平滚动.

The elements scroll horizontally inside another div.

<div id="bottom_end" class="next">
    <a onclick="load_more('/orderby/rising/page/12', '12', 'app_index')"></a>
    <p>Load more<br>in scroll</p>
</div>

推荐答案

您可以使用Jquery来实现.

You can achieve it using Jquery.

$( '#yourdiv').scroll(function() {
   if ( $(this)[0].scrollHeight - $(this).scrollTop() <= $(this).outerHeight()){
       //ajax method for getting your data
       //append response data to your div
    } 
});

请在如何使用jquery实施ajax上进行引用

这篇关于当div滚动到时运行javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆