summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-26 08:38:58 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-26 08:38:58 -0800
commitcc4781d9af3cb57c39a4ac26283f6428ad2aaa60 (patch)
tree5431a8e164a678660a05de8ff12b3085e0b18857 /examples
parent3500cba403fba2e993cb178551ee21cffc5afd4e (diff)
downloadhands-on-scala-js-cc4781d9af3cb57c39a4ac26283f6428ad2aaa60.tar.gz
hands-on-scala-js-cc4781d9af3cb57c39a4ac26283f6428ad2aaa60.tar.bz2
hands-on-scala-js-cc4781d9af3cb57c39a4ac26283f6428ad2aaa60.zip
It works! With animations
Diffstat (limited to 'examples')
-rw-r--r--examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala15
1 files changed, 9 insertions, 6 deletions
diff --git a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
index 19d69f4..83b5860 100644
--- a/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
+++ b/examples/demos/src/main/scala/scrollmenu/ScrollMenu.scala
@@ -23,6 +23,7 @@ class ScrollSpy(structure: Tree[String],
li(
a(
t.value,
+ display := (if (i == -1) "none" else "block"),
href:="#"+Controller.munge(t.value),
cls:="menu-item"
)
@@ -90,21 +91,23 @@ class ScrollSpy(structure: Tree[String],
val childIndexes = children.map(walkIndex)
val childWin = childIndexes.indexWhere(_ != null)
if (childWin != -1) t :: childIndexes(childWin)
- else if (win) Nil
+ else if (win) List(t)
else null
}
val winPath = walkIndex(domTrees)
val winItem = winPath.last.value
def walkTree(tree: Tree[MenuNode], indices: List[Tree[MenuNode]]): Unit = {
- for(item <- indices){
- item.value.frag.classList.remove("hide")
- item.value.frag.classList.remove("selected")
- item.value.frag.children(0).classList.add("pure-menu-selected")
- for(child <- item.children){
+ for(Tree(MenuNode(frag, _, start, end), children) <- indices){
+ frag.classList.remove("hide")
+ frag.classList.remove("selected")
+ frag.children(1).asInstanceOf[dom.HTMLElement].style.maxHeight = (end - start + 1) * 44 + "px"
+ frag.children(0).classList.add("pure-menu-selected")
+ for(child <- children if child.value.frag != indices(1).value.frag){
val childFrag = child.value.frag
childFrag.children(0).classList.remove("pure-menu-selected")
childFrag.classList.add("hide")
+ childFrag.children(1).asInstanceOf[dom.HTMLElement].style.maxHeight = "0px"
if (child.value.start < winItem.start) childFrag.classList.add("selected")
else childFrag.classList.remove("selected")
}