MySql获取所有数据后如何停止滚动功能 [英] How to stop my scroll function once MySql has fetched all the data

查看:240
本文介绍了MySql获取所有数据后如何停止滚动功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此脚本运行正常.但是,一旦MySql获取所有数据,如何停止我的滚动功能和滚动加载器.gif(隐藏).

This script is working fine. But, how to stop my scroll function and the scroll loader .gif (to hidden) once MySql has fetched all the data.

或者,如果有更好的方法可以做到这一点.

Or, if there is a better way to do it.

感谢您的帮助!

JavaScript

Javascript

<script>
$(document).ready(function(){
 var limit = 20;
 var start = 0;
 var action = 'inactive';
 function load_city_data(limit, start)
 {
  $.ajax({
   url:"ps_load_data.php",
   method:"POST",
   data:{limit:limit, start:start},
   cache:false,
   success:function(data)
   {
    $('#load_data').append(data);
    if(data == '')
    {
     $('#load_data_message').html("No Data Found");
     action = 'active';
    }
    else
    {
     $('#imgLoader').html('<img class="animated-gif" src="img/ajax-loader.gif">');
     action = "inactive";
    }
   }
  });
 }

 if(action == 'inactive')
 {
  action = 'active';
  load_city_data(limit, start);
 }
 $(window).scroll(function(){
  if($(window).scrollTop() + $(window).height() > $("#load_data").height() && action == 'inactive')
  {
   action = 'active';
   start = start + limit;
   setTimeout(function(){
    load_city_data(limit, start);
   }, 3000);
  }
 }); 
});
</script>

推荐答案

我最初认为的第3方脚本和CSS(Google API脚本,CDN CSS和CDN脚本)没有任何问题.

There wasn't anything involved with the 3rd party scripts and CSS (Google API script, CDN CSS and CDN script) which I thought initially.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

我全部下载了它们并在本地运行. (仅涉及Google API,与任何CDN脚本无关)

I downloaded them all and run them locally. (Only Google API was involved, nothing to do with any CDN script)

此代码运行良好.停止滚动并立即隐藏ajax-loader.gif.

This code is running fine. Stops the scroll and also hides the ajax-loader.gif now.

发现我的网址中存在问题:"ps_load_data.php"

实际上,我试图运行两个sql查询,因此它没有隐藏我的gif图像.当我将脚本放在其他文件中时,它运行良好.

Actually I was trying to run two sql queries, and hence it wasn't hiding my gif image. When, I put the script in different file, it was working fine.

花费大量时间和精力来了解它与我之前的脚本存在冲突.由于它没有给我任何错误,所以花了很长时间.谢谢!

It took a lot of time and effort to understand that it was conflicting with my earlier script. Since, it didn't gave me any error, it took so long. Thanks!

这篇关于MySql获取所有数据后如何停止滚动功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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