0

What's the correct way to callback from infinity scroll? currently this `

$(function() {
    code(); 
    $('#catview').infinitescroll({ 
        dataType: 'html',
        navSelector: 'div.nextPage',
        nextSelector: 'div.nextPage a:first',
        itemSelector: '#catalogue',
        loading: {
            finishedMsg: '',
            msgText: '',
            img: '/../../../images/loading.gif',
        },
        debug: true,
        animate: true 

    }, $(function() {
        code();
    }));
    });`

Doens't work :( if i set an alert before code() i will see it when page loads and that's it... the other part of the code is :

    function code() {
alert('1')
    $('.teest').caroufredsel({
        direction: 'left',
        circular: true, 
        items: {
            visible: 1, 
            minimum: 2, 
        },
        scroll: {
            fx: 'fade', 
            easing: 'easeOutCubic', 
            duration: 200, 
        },
        auto: {
            duration: 1600
        },
        width: 208,
        height: 265,
        prev: {
            button: '.prev'
        },
        next: {
            button: '.next'
        } 
    });
}

all i see if run those 2 codes is the alert 1 , the caroufredsel working on the first page, if i scroll down to seconds page nothing happens, it just loads

  • Any chance you can set up a jsfiddle? Or give a link to the page in question? – Jake May 20 '13 at 23:22
  • Yes a link.. : http://dokimastiko.14u-fashion.com/shop/cat/65 1/3/2/1 should pop up that's here : $(function() { alert('2'); / code(); })); alert('3'); – Spyros Sakellaropoulos May 20 '13 at 23:29
  • If the alert inside code() is happening, the callback is working. If the rest of the expected behavior isn't happening, it's likely a problem with the rest of the stuff inside code(). My guess is that something is up with your caroufedsel code. – Jake May 20 '13 at 23:33
  • yes but the alert happens BEFORE the infinity scroll gets activated , i noticed this TypeError: J.call is not a function on console, hmm... – Spyros Sakellaropoulos May 20 '13 at 23:35
  • It looks like there's a javascript error whenever new content is loaded. I can't really tell what the problem is because you're using the minified version of the infinitescroll script. If you used the unminified version, it'd be easier to debug. – Jake May 20 '13 at 23:43
  • indeed using the "full" version helps, didn't think about it.. Uncaught TypeError: Object [object Object] has no method 'call' jscroll.js:175 opts.callback jscroll.js:175 infscr_loadcallback jscroll.js:389 infscr_ajax_callback jscroll.js:561 e.extend.each jquery-1.7.2.min.js:2 e.fn.e.each jquery-1.7.2.min.js:2 f.ajax.complete jquery-1.7.2.min.js:4 o jquery-1.7.2.min.js:2 p.fireWith jquery-1.7.2.min.js:2 w jquery-1.7.2.min.js:4 d jquery-1.7.2.min.js:4 (where jscroll is the infinity-scroll plugin) – Spyros Sakellaropoulos May 20 '13 at 23:51
  • See my answer. It may help you – Roopendra May 21 '13 at 07:20

2 Answers2

0

Please try this :-

$(function() {

    $('#catview').infinitescroll({
        dataType: 'html',
        navSelector: 'div.nextPage',
        nextSelector: 'div.nextPage a:first',
        itemSelector: '#catalogue',
        loading: {
            finishedMsg: '',
            msgText: '',
            img: '/../../../images/loading.gif',
        },
        debug: true,
        animate: true 
    },
    function(arrayOfNewElems)
    {
         code();
    });
});

As per Infinite Scroll Jquery documentation call back function change your code

 $(function() {
    code();
 }));

to

function(arrayOfNewElems){
 //here your collaback function
});
Roopendra
  • 7,674
  • 16
  • 65
  • 92
0

Turns out $(function... is readed as object from the javascript engine , and infinity-scroll cannot callback objects. Removing all the $ from the function solve everything