0

I am trying to capture scroll start/stop events for a page control. I want to find out if the last field of the page is in the viewport. The way I am trying to figure out if field is in the viewport is by using the method getBoundingClientRect(). All this works fine but I am not able to invoke this method as I am not able to capture the scroll event. I intend to call this method inside the event handler for scrollstop, so I know the user has stopped the scroll and now is the time to check if the field is reached.

Using this link to find out the events that can be handled:

https://sapui5.hana.ondemand.com/#/api/module:sap/ui/events/ControlEvents

It is a touch device so need to figure out how to handle touch event as well.

Currently, below is the code for mouse scroll which is not working. Other events like clicked, mouseover are working.

How to get onscrollstart and onscrollstop to work?

In controller.js

onAfterRendering: function () {

        controller.getView().byId("PAGECONTROLID").addEventDelegate({
            onclick: function(){
                console.log("clicked"); // works on all panels within the page
            },
            onmouseover: function(){
                console.log("mouseover"); // works on all panels within the page
            },
            onscroll: function(){
                console.log("onscroll"); // IS NOT CORRECT EVENT, but tried it anyway
            },
            onscrollstart: function(){
                console.log("scroll start"); // DOES NOT WORK
            },
            onscrollstop: function(){
                console.log("scroll stop"); // DOES NOT WORK
            }
        })
THI
  • 355
  • 11
  • 40
  • 1
    Does this answer your question? [UI5: Check if a control is currently rendered and visible](https://stackoverflow.com/questions/48567767/ui5-check-if-a-control-is-currently-rendered-and-visible) – Boghyon Hoffmann Aug 04 '21 at 13:04
  • 2
    As suggested by the [answer](https://stackoverflow.com/a/54038430/5846045) there, `IntersectionObserver` can help to detect whether the target HTMLElement is in the viewport or not. Give it a try – Boghyon Hoffmann Aug 04 '21 at 13:06
  • 1
    Thank you for the reply. That answers my question as well as learnt about IntersectionObserver. Thank you – THI Aug 10 '21 at 01:25
  • Then please consider upvoting that answer and marking this question as a duplicate. – Boghyon Hoffmann Aug 10 '21 at 07:24

0 Answers0