Search code examples
phpjqueryrefreshjscrollpane

jScrollPane resets back to original after class refresh


I have a site which has a section containing a Youtube video and the comments for it. The comments which are inside a div class get refreshed every 5 minutes using the following code below:

<script type="text/javascript">
    setInterval(function(){
        $(".comments").load("test.php .comments");
    }, 300000);
</script>

To scroller for the comments is powered by jScrollPane. However after after the comments have refreshed, the scroller disappears and reverts back to the original browser scroller. I have tried adjusting the script above so that is also refreshed the scroller but no hope there.

The container for the comments is as shown below

    echo '<div class="comments scroll">';

        $feedURL = curl_init("http://gdata.youtube.com/feeds/api/videos/{$cut}/comments");
            curl_setopt($feedURL, CURLOPT_RETURNTRANSFER, true);
            curl_setopt($feedURL, CURLOPT_HEADER, 0);

        $data = curl_exec($feedURL);
            curl_close($feedURL);

        $sxml = new SimpleXmlElement($data);            

        foreach($sxml->entry as $comment)
            {
            echo '<p>',$comment->content,'</br><i>',$comment->author->name,'</i></br>','</p>';
            }
    echo '</div>';  

Could someone please advise on how to work around this error. Thanks in advance.


Solution

  • <script type="text/javascript">
        setInterval(function(){
            $(".comments").load("test.php");
    
            $('.scroll').jScrollPane();
        }, 300000);   
    </script>