Replace auto action with onclick

Replace auto action with onclick

Hi everyone.

I'm totally new to jQuery.

I used this snippet of ode (had to addapt it) to autoload (think Twitter) new posts on my page when scrolling.

Since this is ressource heavy for my server when a user scrolls fast, I want it to be activated when cliking on a button, lets say <button id="load_more">Load more</button>

Can anyone help me convert mine ? I can't get it to work...

Here is the code I use for autoscroll :

  1. <?php
  2.   $maxPage = $this->Paginator->counter('%pages%');
  3.   ?>
  4.   <script type="text/javascript">
  5.   var lastX = 0;
  6.   var currentX = 0;
  7.   var page = 1;
  8.    
  9.   $(window).scroll(function () {
  10.   if (page < <?php echo $maxPage;?>) {
  11.   currentX = $(window).scrollTop();
  12.   if (currentX - lastX > 150 * page) {
  13.   lastX = currentX - 150;
  14.   page++;
  15.   $("#busy-indicator").fadeIn();
  16.   $.get('<?php echo $this->Html->url('/users/getmore_timeline/'.$this->Session->read('Auth.User.id')); ?>/page:' + page, function(data) {
  17.   setTimeout(function(){
  18.   $('#postList').append(data);
  19.   var bi =  $("#busy-indicator");
  20.         bi.stop(true, true);
  21.         bi.fadeOut();
  22.   }, 500);
  23.   });
  24.   }
  25.   }
  26.   });
  27.   </script>

MAny thanks for your time and help !