Scroll down the page after rendering

I am currently working on a messaging system using Backbone. I want to scroll to the last item in a CollectionView on a render.

I can make this work after clicking the link on the page, but I want this to happen on the rendering of the view.

Here is what I use in a link that works:

document.getElementById('message-new-conversation-dialog').scrollIntoView();

Here's a definition of the form:

var ConversationView = LSmixBB.CollectionView.extend({

        itemView: MessageView,
        template: "#message-conversation-template",
        onRender: function(){
            document.getElementById('message-new-conversation-dialog').scrollIntoView();
            document.getElementById('global-column-middle-footer1').scrollIntoView();
        }

    });

I assume it doesn't work because there is nothing on the page inside onRender?

I am very new to web development, so be gentle!

In any case, I would really appreciate any help!

+3
source share
2 answers

If you use Backbone, you have access to the Underscore _defer function: http://underscorejs.org/#defer

, DOM , , , this

_.defer(function(caller){
      //caller is now a reference to the scope where you declared this
}, this);

, , , DOM. , , .

: jQuery.ready , , , _defer ,

+5

, - , -, . , , scrollIntoView, , , 200 , .

, onRender.

, , !

+3

All Articles