added code snippet

This commit is contained in:
Andreas Rumpf 2017-04-15 11:18:15 +02:00
commit 5bd43f13f9

View file

@ -111,3 +111,22 @@ when false:
if plugins.len > 0:
plugins[0][1]()
var
images: seq[cstring] = @[cstring"a", "b", "c", "d"]
proc carousel*(): VNode =
var currentIndex = 0
proc next(ev: Event; n: VNode) =
currentIndex = (currentIndex + 1) mod images.len
proc prev(ev: Event; n: VNode) =
currentIndex = (currentIndex - 1) mod images.len
result = buildHtml(tdiv):
text images[currentIndex]
button(onclick = next):
text "Next"
button(onclick = prev):
text "Previous"