Jump to content

HTMLFrame Scrolling Contents: How Do I Capture The Scrollbar Scrolling Events (eg. Drag: Start, Stop Co-Ordinates) ?


andyhill

Recommended Posts

This is one of my many attempts but it fails, any sugestions ?


                                   s:= 'beforeInit=function beforeInit(sender, config)'+
                                         '{'+

                                         '  config:'+
                                         '  {'+
                                         '    refs:'+
                                         '    {'+
                                         '      list: ''...'';'+
                                         '    },'+
                                         '    control:'+
                                         '    {'+
                                         '      list:'+
                                         '      {'+
                                         '        initialize: ''onListInit'';'+
                                         '      }'+
                                         '    }'+
                                         '  },'+

                                         '  onListInit: function()'+
                                         '  {'+
                                         '    var scroller = this.getScrollable().getScroller();'+
                                         '    scroller.on(''scrollstart'', this.onNnListScrollStart, this);'+
                                         '    scroller.on(''scrollend'',   this.onNnListScrollEnd,   this);'+
                                         '  },'+

                                         '  onNnListScrollStart: function(scroller, x, y)'+
                                         '  {'+
                                         '    console.log(''START SCROLL'');'+
                                         '  },'+

                                         '  onNnListScrollEnd: function(scroller, x, y)'+
                                         '  {'+
                                         '    console.log(''scroll x:''+x);'+
                                         '    console.log(''scroll y:''+y);'+
                                         '    var bottom = scroller.maxPosition.y;'+
                                         '    var top    = scroller.minPosition.y;'+
                                         '    var isScrollUp   = scroller.dragDirection.y === -1;'+
                                         '    var isScrollDown = scroller.dragDirection.y === 1;'+
                                         '    if (bottom === y && isScrollDown)'+
                                         '    {'+
                                         '      console.log(''BOTTOM'');'+
                                         '    }'+
                                         '    if (top === y && isScrollUp)'+
                                         '    {'+
                                         '      console.log(''TOP'');'+
                                         '    }'+
                                         '    console.log(''END SCROLL'');'+
                                         '  }'+

                                         '}';

HTMLFrame.ClientEvents.UniEvents.Add(s);
 

Link to comment
Share on other sites

  • 2 weeks later...
1 hour ago, andyhill said:

Any progress ?

Sorry for the late reply.

One possible approach, you can try...

1. UniHTMLFrame1.HTML := ...

2. UniHTMLFrame1.AutoScroll = True

3. UniHTMLFrame1.ClientEvents.ExtEvents -> 

function boxready(sender, width, height, eOpts)
{
    if (sender.getScrollable()) {
       sender.getScrollable().on('scrollend', function(cmp, x, y) {
           ajaxRequest(sender, 'scrollend', ['x='+x, 'y='+y])
       });
       sender.getScrollable().on('scrollstart', function(cmp, x, y) {
           ajaxRequest(sender, 'scrollstart', ['x='+x, 'y='+y])
       })
   }
}

4. 

procedure TMainForm.UniHTMLFrame1AjaxEvent(Sender: TComponent;
  EventName: string; Params: TUniStrings);
begin
  if EventName = 'scrollstart' then
    UniMemo1.Lines.Add('scrollstart: '+Params.Values['x'] + ', ' + Params.Values['y'])
  else if EventName = 'scrollend' then
    UniMemo1.Lines.Add('scrollend: '+Params.Values['x'] + ', ' + Params.Values['y'])
end;

 

Link to comment
Share on other sites

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...