javascript

queres fazer o efeito de switch dos botões ( quando fazes hover ) ?
ou queres fazer o efeito de quando abres a página ele descer até ao centro da página ?

estás a utilizar alguma framework ? caso não estejas, podes usar uma ou preferes javascript puro ?

cumps ;)
 
Em javascript puro não faço ideia como seja, mas convêm começar com o HTML/CSS. Eu faria:

Código:
<a href="#" class="sideButton">
  <span class="button1"></span>
  <span class="button2"></span>
</a>

e depois os estilos...tirando os detalhes, o posicionamento do botão seria:
position: fixed;
top: 0;

o algoritmo seria algo parecido com isto:

quando a página abrir fazer um efeito que mude o top de 0 para 50%. em mootools seria:

Código:
<script type="text/javascript">
window.addEvent( 'domready', function(){
  var button = $$('.sideButton.')[0];[FONT=monospace]
[/FONT]  var myFx = new Fx.Tween( button );
  myFx.set('top', '50%' );
});
</script>

depois o rollover depende de como tiveres os estilos

se quiseres posta aqui o html/css desse botão, porque isso dá para fazer de algumas maneiras, depende muito da marcação

cumps ;)
 
Há algum tempo também tiver de fazer algo semelhante a essa animação, e um dos requisitos do cliente era de que não podia recorrer a frameworks javascript (não faço ideia porquê :P)

Adaptei ao script apenas àquelas 2 imagens da zon.pt (nomes do ficheiro e dimensões das imagens); mas basicamente faz algo parecido, apesar de não ser tão fluída a animação :)

Código:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title></title>

    <style type="text/css">
      #slidebar{ overflow: hidden; }
      #slidebar a{
        display: block; background-repeat: no-repeat; outline: none;
      }
      #slidebar a#top{
        background-image: url("http://webcare.byside.com/agent/liveagentskins/zon2/bg.png"); z-index: 1; width: 125px;
      }
      #slidebar a#bottom{
        background-image: url("http://webcare.byside.com/agent/liveagentskins/zon2/bg2.png"); right: -160px;
      }
      #slidebar ul{display: inline; list-style: none;}
      #slidebar, #slidebar a{height: 83px; position: absolute; right: 0; top: 0;}
      #slidebar, #slidebar #bottom{width: 160px;}
    </style>

    <script type="text/javascript">
      window.onload = function() {

        var DummyAnimations = function() {
          var
            $ = function(o) { return document.getElementById(o) || null; },

            _view_height = function(){
              return window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
            },

            _Top_Middle = function(o, step, speed, to, value){
              var
                el = (typeof o === "object") ? o : $(o),
                value = value || 0,
                to = to || ((_view_height() - el.offsetHeight) / 2),
                _animate = function(value) {
                  var
                    self = arguments.callee,
                    interval = setTimeout(function() {
                      if (value < to) {
                        value += step;
                        el.style.top = value + "px";
                        self(value);
                      }
                      else {
                        clearTimeout(interval);
                      }
                    }, speed);
                }(value);
            },

            _SwitchBackground = function(o, o_bottom, step, speed){
              var
                el = (typeof o === "object") ? o : $(o),
                el_bottom = (typeof o_bottom === "object") ? o_bottom : $(o_bottom),
                el_width = el.offsetWidth,
                el_bottom_width = el_bottom.offsetWidth,
                _animate = function(step, speed, _width, _el_hide, _el_show, value) {
                  var
                    value = value || 0,
                    self = arguments.callee,
                    interval = setTimeout(function() {
                      if (value > -_width) {
                        value -= step;
                        _el_hide.style.right = value + "px";
                        _el_show.style.right = Math.abs(value) - _width + "px";
                        self(step, speed, _width, _el_hide, _el_show, value);
                      }
                      else {
                        clearTimeout(interval);
                      }
                    }, speed);
                };

              el.onmouseover = function(e){
                e = e || window.event;
                _animate(step, speed, el_width, el, el_bottom);
              };

              el_bottom.onmouseout = function(e){
                e = e || window.event;
                _animate(step, speed, el_bottom_width, el_bottom, el);
              };

              el.onclick = function(e){
                e = e || window.event;
                if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
              };

              el_bottom.onclick = function(e){
                e = e || window.event;
                alert("acção ....");
                if (e.preventDefault) { e.preventDefault(); } else { e.returnValue = false; }
              };
            };

            return { TopMiddle: _Top_Middle, Switch: _SwitchBackground };
        }();

        DummyAnimations.TopMiddle("slidebar", 25, 50);
        DummyAnimations.Switch("top", "bottom", 5, 25);
      };

    </script>

</head>
<body>
  <div id="slidebar">
    <ul>
      <li><a href="#" id="top"></a></li>
      <li><a href="#" id="bottom"></a></li>
    </ul>
  </div>
</body>
</html>
 
Back
Topo