2010-11-19 6 views

risposta

48

Se vuoi includere la libreria jQuery UI, oltre a jQuery, puoi semplicemente utilizzare hide(), with additional arguments, come segue:

$(document).ready(
    function(){ 
     $('#slider').click(
      function(){ 
       $(this).hide('slide',{direction:'right'},1000); 

      }); 
    }); 

JS Fiddle demo.


Senza usare jQuery UI, si potrebbe raggiungere il tuo obiettivo usando solo animate():

$(document).ready(
    function(){ 
     $('#slider').click(
      function(){ 
       $(this) 
        .animate(
         { 
          'margin-left':'1000px' 
          // to move it towards the right and, probably, off-screen. 
         },1000, 
         function(){ 
          $(this).slideUp('fast'); 
          // once it's finished moving to the right, just 
          // removes the the element from the display, you could use 
          // `remove()` instead, or whatever. 
         } 
         ); 

      }); 
    }); 

JS Fiddle demo

Se si sceglie di utilizzare jQuery UI, allora vi consiglio il collegamento al Codice ospitato da Google, al numero: https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js

+1

Sto cercando di stare lontano dall'interfaccia utente jQuery – Webnet

+1

@Webnet, quindi quest'ultimo codice/demo dovrebbe funzionare ... –

12

Un'altra soluzione è usare .animate() e il CSS appropriato.

ad es.

$('#mydiv').animate({ marginLeft: "100%"} , 4000); 

+0

Che non sembra funzionare nel mio esempio .... http : //jsfiddle.net/Webnet/DtzAw/ – Webnet

+0

@Webnet: ma nel [esempio di collegamento a] (http://jsfiddle.net/Webnet/DtzAw/) (nel tuo commento precedente), non apparirà per chiamare ['animate()'] (http://api.jquery.com/animate/). –

+0

Spiacente, non ha collegato la revisione corretta .... http://jsfiddle.net/Webnet/DtzAw/1/ – Webnet

Problemi correlati