0

Scrolling Event not getting called for layout

asked 2022-02-22 17:24:02 +0800

SahilGupta29 gravatar image SahilGupta29
1

Product query context:

  1. ZK Version: '8.0.1'
  2. Component Support: Center,Div,Vlayout

Query:

We are trying to call the scrolling event for the center layout in the application. But the scroll event is not getting called.

<center id="mainlayoutCenterCanvas" xmlns:w="client" w:onScroll='console.log("scroll a")'autoscroll="true">
        <div id="mainLayoutFullfill" xmlns:w="client" w:onScroll='console.log("scroll b")' fulfill="=../WEB-INF/zul/qa/layout/center.zul"/>
</center>

And in the center.zul we have :

<vlayout id="centerAreaCanvas" xmlns:w="client" w:onScroll='console.log("scroll center")'>

For all the above components we have added an event listener in Java also as:

public Center getMainlayoutCenterCanvas() {
    Center mainlayoutCenterCanvas = (Center)getFellowIfAny("mainlayoutCenterCanvas");
    mainlayoutCenterCanvas.addEventListener(Events.ON_SCROLL, new EventListener<Event>() {
        @Override
        public void onEvent(Event event) throws Exception {
            // TODO Auto-generated method stub
            System.out.print("check");
        }
    });
    mainlayoutCenterCanvas.addEventListener(Events.ON_SCROLLING, new EventListener<Event>() {
        @Override
        public void onEvent(Event event) throws Exception {
            // TODO Auto-generated method stub
            System.out.print("check");
        }
    });
    return mainlayoutCenterCanvas;
}

Div mainLayoutFullfill;
public void addListenerToCenter() {
    if(centerAreaCanvas == null) {
        centerAreaCanvas = (Vlayout)getFellowIfAny("centerAreaCanvas");
        centerAreaCanvas.addEventListener(Events.ON_SCROLL, new EventListener<Event>() {
            @Override
            public void onEvent(Event event) throws Exception {
                // TODO Auto-generated method stub
                System.out.print("check a");
            }
        });
        centerAreaCanvas.addEventListener(Events.ON_SCROLLING, new EventListener<Event>() {
            @Override
            public void onEvent(Event event) throws Exception {
                // TODO Auto-generated method stub
                System.out.print("check a");
            }
        });
    }
    if(mainLayoutFullfill == null) {
        mainLayoutFullfill = (Div)getFellowIfAny("mainLayoutFullfill");
        mainLayoutFullfill.addEventListener(Events.ON_SCROLL, new EventListener<Event>() {
            @Override
            public void onEvent(Event event) throws Exception {
                // TODO Auto-generated method stub
                System.out.print("check b");
            }
        });
        mainLayoutFullfill.addEventListener(Events.ON_SCROLLING, new EventListener<Event>() {
            @Override
            public void onEvent(Event event) throws Exception {
                // TODO Auto-generated method stub
                System.out.print("check b");
            }
        });

    }
}

But none of the events are getting called. What is wrong here What can we do? I need to get Y position(Vertical scroll position on scrolling and save it)

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2022-02-24 18:20:54 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

updated 2022-02-24 19:56:22 +0800

zul.layout.LayoutRegion._doScroll() fires events with zWatch

_doScroll: function () {
    zWatch.fireDown('onScroll', this);
},

You need to listen with zWatch

Because fireDown() only invokes a listener on an event's target's descendants, you need to register a listener on the center's child component.

<borderlayout>
    <north height="500px" autoscroll="true">
        <div height="1000px">

            north
        </div>
    </north>
    <center id="mainlayoutCenterCanvas" autoscroll="true">
        <div id="main" height="1000px">
            content in center
        </div>
    </center>
    <south height="300px">
        south
    </south>
</borderlayout>
<script defer="true" src="scrollListener.js"/>

scrollListener.js

var div = zk.Widget.$('$main');
div.onScroll = function(controller){
        console.log(controller);
}

zWatch.listen({
    onScroll: div,
});
link publish delete flag offensive edit

answered 2022-03-07 16:54:53 +0800

hawk gravatar image hawk
3250 1 5
http://hawkphoenix.blogsp... ZK Team

get vertical scroll position

div.onScroll = function(controller){
        console.log(controller.origin.$n('cave').scrollTop);
}
link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2022-02-22 17:24:02 +0800

Seen: 8 times

Last updated: Mar 07 '22

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More