summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-26 03:49:02 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-26 03:49:02 -0800
commitcc3df84442cc78a7af99c793485185829ccdcc4d (patch)
tree56781360e6e909bdb8f29213ca804f4bb1470125 /examples
parent0ae3b5b47a7e1a3a8ae31817bc7b10ca9c054f54 (diff)
downloadhands-on-scala-js-cc3df84442cc78a7af99c793485185829ccdcc4d.tar.gz
hands-on-scala-js-cc3df84442cc78a7af99c793485185829ccdcc4d.tar.bz2
hands-on-scala-js-cc3df84442cc78a7af99c793485185829ccdcc4d.zip
fix scrolling for reals
Diffstat (limited to 'examples')
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala17
1 files changed, 9 insertions, 8 deletions
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
index 7d718e2..1938c67 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
@@ -68,6 +68,7 @@ class ScrollSpy(structure: Tree[String],
dom.requestAnimationFrame((d: Double) => start())
}
}
+ private[this] var previousId = ""
private[this] def start() = {
scrolling = false
def scroll(el: dom.Element) = {
@@ -95,15 +96,15 @@ class ScrollSpy(structure: Tree[String],
winFound = winFound | newWinFound
}
if (!winFound) {
- // This means it's the leaf element, because it won but there
- // aren't any children which won, so it must be the actual leaf
- tree.children.foreach(_.value.frag.classList.remove("selected"))
+ if (previousId != itemId){
+ previousId = itemId
+ // This means it's the leaf element, because it won but there
+ // aren't any children which won, so it must be the actual leaf
+ tree.children.foreach(_.value.frag.classList.remove("selected"))
+ scroll(menuItem.children(0))
- val top = main.scrollTop
- dom.location.hash = itemId
- main.scrollTop = top
-
- scroll(menuItem.children(0))
+ dom.history.replaceState(null, null, "#" + itemId)
+ }
}
menuItem.children(0).classList.add("pure-menu-selected")
}else{