首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在滚动时使用ajax加载内容

在滚动时使用ajax加载内容
EN

Stack Overflow用户
提问于 2010-07-20 01:59:43
回答 4查看 9.5K关注 0票数 1

我使用jQuery工具插件作为图像滑块(image here),但由于大量的图像,我需要一次加载几个。因为它是javascript编码的,据我所知我不能知道滚动的位置。我想在最后一张图片或类似的东西出现时加载它们。我不知道我放在哪里,事件监听器也不知道。

下面是我的代码http://jsfiddle.net/PxGTJ/

请给我一点光!

EN

Stack Overflow用户

发布于 2010-07-20 03:27:47

这可以通过以下方式实现:

代码语言:javascript
运行
复制
//When the DOM is ready...
$(document).ready(function() {

   //When the user scrolls...
   $(window).scroll(function() {
       var tolerance = 800,
           scrollTop = $(window).scrollTop();

       //If the the distance to the top is greater than the tolerance...
       if(scrollTop > tolerance) {

           //Do something. Ajax Call, Animations, whatever.

       }
   }) ;
});

这应该能起到作用。

编辑:因为您没有使用原生滚动,所以我们必须对代码进行一些修复:

代码语言:javascript
运行
复制
//When the DOM is ready...
$(document).ready(function() {

   //When the user scrolls...
   $("div.scrollable").find(".next").click(function() {
       var tolerance = 800,
           // The absolute value of the integer associated 
           // to the top css property
           scrollTop = Math.abs(parseInt($("div.items").css("top")));

       //If the the distance to the top is greater than the tolerance...
       if(scrollTop > tolerance) {

           //Do something. Ajax Call, Animations, whatever.

       }
   }) ;
});
票数 3
EN
查看全部 4 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3283669

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档