Exemplo n.º 1
0
 @Override
 public HandlerRegistration addScrollHandler(ScrollHandler scrollHandler) {
   return addHandler(scrollHandler, ScrollEvent.getType());
 }
Exemplo n.º 2
0
 public HandlerRegistration addScrollHandler(ScrollHandler handler) {
   return addDomHandler(handler, ScrollEvent.getType());
 }
Exemplo n.º 3
0
  @Override
  protected void start() {
    root.add(loginBar);

    goTop.addStyleName(style.gotop());
    goTop.addDomHandler(
        new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
            root.getElement().setScrollTop(0);
          }
        },
        ClickEvent.getType());

    gotoTask =
        new DelayedTask() {
          @Override
          public void onExecute() {
            if (!gotoShowing && scrollTop >= 800) {
              goTop.addStyleName(style.gotopshow());
              gotoShowing = true;
            } else if (scrollTop < 800 && gotoShowing) {
              goTop.removeStyleName(style.gotopshow());
              gotoShowing = false;
            }
          }
        };

    navTask =
        new DelayedTask() {
          @Override
          public void onExecute() {
            if (scrollTop >= navMix && scrollTop <= navMax) {
              return;
            }
            currentli.removeClassName(style.active());
            int i = 0;
            while (i < pns.size()) {
              PositionNav nav = pns.get(i);
              navMix = nav.getScrollTop() - OFFSET;
              navMax =
                  ((i == (pns.size() - 1))
                          ? root.getElement().getScrollHeight()
                          : pns.get(i + 1).getScrollTop())
                      - OFFSET;
              if (scrollTop >= navMix && scrollTop <= navMax) {
                currentli = nav.getElm();
                break;
              }
              i++;
            }
            currentli.addClassName(style.active());
          }
        };

    initPostion();

    root.addDomHandler(
        new ScrollHandler() {
          @Override
          public void onScroll(ScrollEvent event) {
            scrollTop = event.getRelativeElement().getScrollTop();
            gotoTask.delay(100);
            navTask.delay(30);
          }
        },
        ScrollEvent.getType());
  }