private void initPostion() { if (pns == null) { pns = new ArrayList<PositionNav>(); } NodeList<Node> nodes = content.getChildNodes(); for (int i = 1; i < nodes.getLength(); i = i + 2) { Element elm = nodes.getItem(i).<Element>cast(); final int absoluteTop = elm.getAbsoluteTop() - OFFSET; LIElement li = Document.get().createLIElement().cast(); li.setInnerHTML(elm.getId()); EventGenerator.onClick( li, new Function() { @Override public void f(Event e) { root.getElement().setScrollTop(absoluteTop); } }); ul.appendChild(li); pns.add(new PositionNav(absoluteTop, li)); } currentli = pns.get(0).getElm(); currentli.addClassName(style.active()); }
@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()); }