Advertisement
vyoumans

Dart.js SLIDER example

Jul 18th, 2014
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. This is a slider example.
  2.  
  3.  
  4. Map slides = {
  5. 'slide1': 'This is test slide 1. <button id="slide2">To 2</button><button id="slide5, nexttag="slide1">To 5</button>',
  6.  
  7. observe the next tag = "slide1" this is a tag that I inserted as an extra. I want to pass this tag to my code. But not working.
  8. what is the URL of the documentation I should be looking at to modify this?
  9.  
  10.  
  11.  
  12. //==========================================================================
  13. import 'dart:html';
  14.  
  15. Map slides = {
  16. 'slide1': 'This is test slide 1. <button id="slide2">To 2</button><button id="slide5", nexttag="slide1">To 5</button>',
  17. 'slide2': 'This is test slide 2. <button id="slide3">To 3</button><button id="slide4", nexttag="slide4">To 4</button>',
  18. 'slide3': 'This is test slide 3. <button id="slide4">To 4</button><button id="slide1", nexttag="slide1">To 1</button>',
  19. 'slide4': 'This is test slide 4. <button id="slide5">To 5</button><button id="slide2", nexttag="slide2">To 2</button>',
  20. 'slide5': 'This is test slide 5. <button id="slide1">To 1</button><button id="slide3", nexttag="slide3">To 3</button>'
  21. };
  22.  
  23. void main() {
  24. var c = querySelector('.container');
  25. // toList to get a real list not a HtmlCollection.
  26. var active = c.children[0];
  27. var ready = c.children[1];
  28.  
  29. change(String to){
  30. // Gives ready new html
  31. ready.innerHtml = slides[to];
  32. ready.querySelectorAll('button').forEach((Element button){
  33. //button.onClick.listen((_) => change(button.id));
  34. //Is it posible to add a tag to the Button, and use that as the next navigation link?
  35. button.onClick.listen((_) => change(button.nexttag));
  36. });
  37.  
  38. // Activate
  39. ready.style.removeProperty('transition-duration');
  40. ready.style.left = '0%';
  41. active.style.left = '-100%';
  42.  
  43. ready.onTransitionEnd.first.then((_){
  44. // swap active and ready. The animation is done.
  45. var temp = ready;
  46. ready = active;
  47. active = temp;
  48.  
  49. //disable transition on ready so i can jump it back to start
  50. ready.style.transitionDuration = "0";
  51. ready.style.left = '100%';
  52.  
  53. //Clears readys content
  54. ready.innerHtml = '';
  55.  
  56. });
  57. }
  58.  
  59. // sets active upp with the fist slide.
  60. active.innerHtml = slides['slide1'];
  61. active.querySelectorAll('button').forEach((Element button){
  62. button.onClick.listen((_) => change(button.id));
  63. });
  64. active.style.left = '0%';
  65.  
  66. // move ready to start.
  67. ready.style.left = '100%';
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement