madrobby (owner)

Revisions

gist: 132653 Download_button fork
public
Public Clone URL: git://gist.github.com/132653.git
Embed All Files: show embed
JavaScript #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
TransitionExample: function(element){
    var type = element.up().down('.ebnf').innerHTML.gsub(/s2\.fx\.Transitions\./,'').split('(').first(),
      transition = s2.fx.Transitions[type], active = false;
      
    var values = $R(0,200).map(function(v){ return transition(v/200)*200; }),
      min = Math.min(0, values.min()), max = Math.max(200, values.max());
 
    if (min==max) {
      min = 0; max = 200;
    }
    
    var factor = 200/(max-min), grid = '<span style="bottom:'+((0-min)*factor).round()+'px">0</span>'+
      '<span style="bottom:'+((200-min)*factor).round()+'px">1</span>',
      graph = $R(0,200).map(function(v){
        return '<div style="left:'+v+'px;bottom:'+((values[v]-min)*factor).round()+'px;height:1px"></div>';
      }).join('') + '<div class="indicator" style="display:none"></div><div class="marker" style="display:none"></div><div class="label"></div>';
      
      
    var interactive = '<div class="interactive">'+
      '<div class="movement">movement</div>' +
      '<div class="color">color</div>' +
      '<div class="size">size</div>' +
      '</div>';
      
    element.innerHTML = grid + graph + interactive;
    
    var effectM, effectC, effectS,
      interactive = element.down('div.interactive'),
      movement = interactive.down('div.movement'),
      color = interactive.down('div.color'),
      size = interactive.down('div.size'),
      indicator = element.down('div.indicator'),
      marker = element.down('div.marker'),
      label = element.down('div.label');
      
    var demoTransition = function(pos){
      var value = transition(pos);
      indicator.style.cssText += ';left:'+(pos*200).round()+'px';
      marker.style.cssText += ';left:'+(pos*200).round()+'px;bottom:'+(((value*200)-min)*factor).round()+'px';
      return value;
    }
    
    interactive.observe('mouseenter', function(){
      interactive.addClassName('active');
      indicator.show();
      marker.show();
      var durations = [.2, .5, 1, 3, 5], i = -1, duration, delay = 0;
      function animate(){
        duration = durations[++i%durations.length];
        effectM = new s2.fx.Morph(movement, {
          style: 'left:268px', transition: demoTransition, duration: duration, delay: delay,
          before: function(){
            label.innerHTML = duration + 's';
            movement.setStyle('left:20px')
          },
          after: function(){ if(active) animate(); }
        });
        effectM.play();
        effectC = new s2.fx.Morph(color, {
          style: 'background-color:#9D74D4', duration: duration, delay: delay, transition: transition,
          before: function(){ color.setStyle('background-color:#ABD474') }
        });
        
        effectC.play();
        effectS = new s2.fx.Morph(size, {
          style: 'top:20px;left:390px;width:135px;font-size:200%;height:120px', duration:duration, delay: delay, transition: transition,
          before: function(){ size.setStyle('top:60px;left:450px;margin:0;width:30px;height:30px;font-size:100%') }
        });
        effectS.play();
        delay = 1;
      }
      active = true;
      animate();
    }).observe('mouseleave', function(){
      i = -1;
      label.innerHTML = '';
      indicator.hide();
      marker.hide();
      interactive.removeClassName('active');
      if(effectM) effectM.cancel();
      if(effectC) effectC.cancel();
      if(effectS) effectS.cancel();
      movement.setStyle('left:20px');
      color.setStyle('background-color:#fff');
      size.setStyle('top:60px;left:450px;width:30px;height:30px;font-size:100%');
      active = false;
    });
  },