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 :
- <?php
- $maxPage = $this->Paginator->counter('%pages%');
- ?>
- <script type="text/javascript">
- var lastX = 0;
- var currentX = 0;
- var page = 1;
-
- $(window).scroll(function () {
- if (page < <?php echo $maxPage;?>) {
- currentX = $(window).scrollTop();
- if (currentX - lastX > 150 * page) {
- lastX = currentX - 150;
- page++;
- $("#busy-indicator").fadeIn();
- $.get('<?php echo $this->Html->url('/users/getmore_timeline/'.$this->Session->read('Auth.User.id')); ?>/page:' + page, function(data) {
- setTimeout(function(){
- $('#postList').append(data);
- var bi = $("#busy-indicator");
- bi.stop(true, true);
- bi.fadeOut();
- }, 500);
- });
- }
- }
- });
- </script>
MAny thanks for your time and help !