Jump to content

Design-time vertical scroll to last row added in component


fiorilli

Recommended Posts

Hi, I already tested the components:


- TUniURLFrame
- TUniHTMLFrame
- TUniHTMLMemo


The HTML property or Lines according to the above component injects the HTML of messages resulting from a Chat. When you enter several messages, vertical scrolling is displayed. The problem presented and not found in the research conducted in the forum is about:


- Design time scrolling to the last line added in the component if the scrolling is already at the end, otherwise do nothing, how to do it?

Link to comment
Share on other sites

The vertical scroll having the behavior of the Skype chat window for example. When you receive a message if scrolling is at the end, it continues at the end, if it is not at the end because you are reading previous messages, the new message is added and the vertical scroll remains in the same place.

Link to comment
Share on other sites

55 minutes ago, fiorilli said:

The vertical scroll having the behavior of the Skype chat window for example. When you receive a message if scrolling is at the end, it continues at the end, if it is not at the end because you are reading previous messages, the new message is added and the vertical scroll remains in the same place.

Please make a simple testcase with TUniHTMLMemo for example, to see what problem you are facing.

Link to comment
Share on other sites

51 minutes ago, fiorilli said:

Hello, any news from the example above?

If I understand you correctly, try to analyze and modify this code for your case...

1. UniHTMLMemo2.ClientEvents.ExtEvents ...

function afterrender(sender, eOpts)
{
    var me=sender;
    me.scrollToEndIfNeeded = function() {
        if (me.getWin().document.body.scrollHeight-me.getWin().scrollY<200) {            
            me.getWin().scrollTo(0, me.getWin().document.body.scrollHeight);
        }
    }
}

2. Use

procedure TMainForm.UniBitBtn4Click(Sender: TObject);
begin
  Inc(j);
  UniHTMLMemo2.Lines.Add('<br>' + IntToStr(j));
  UniHTMLMemo2.JSInterface.JSCallDefer('scrollToEndIfNeeded', [], 20);
end;

 

Link to comment
Share on other sites

  • 5 months later...

Hi Sherzod,

    Will the above code work in a TUniHTMLFrame as I would like to do a similar thing using a HTMLFrame?

     If not do you have some code that will work with a TUniHTMLFrame?

Thanks

 

Link to comment
Share on other sites

Hi Sherzod,

  I tried to use the above code in a test app with build 1481 but it doesn't have JSCallDefer?

  Is it possible to position the scrollbar so it is at the bottom when things are added so that whatever was added is always visible?

 At the moment when the scrollbars are visible and I add things to the frame the frame does not show the last thing added unless I manually scroll to the end.

Link to comment
Share on other sites

Hi Sherzod,

  Attached is a sample application.

  If you keep pressing the Add Chat button the scrollbars will eventually appear and the text added at the bottom will not be visible.

  I would like the scrolling to happen automatically when content is added to the bottom so it's always visible.

Example.zip

Link to comment
Share on other sites

4 hours ago, mos said:

Attached is a sample application.

  If you keep pressing the Add Chat button the scrollbars will eventually appear and the text added at the bottom will not be visible.

  I would like the scrolling to happen automatically when content is added to the bottom so it's always visible.

Example.zip

Hi,

Thanks, 

I will check.

Link to comment
Share on other sites

4 hours ago, mos said:

  I would like the scrolling to happen automatically when content is added to the bottom so it's always visible.

Try this:

procedure TMainForm.UniHTMLFrame1UpdateHtml(Sender: TObject);
begin
  (Sender as TUniHTMLFrame).JSInterface.JSCode(#1'.body.dom.scrollTo(0, '#1'.body.dom.scrollHeight);');
end;

 

Link to comment
Share on other sites

  • 3 years later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...