Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    [JS] effetto movimento DIV accelerazione/decelerazione

    ciao a tutti, ho un layer posizionato i maniera assoluta e fatto uscire dallo schermo per renderlo nascosto, tramite js lo faccio riapparire agendo sulla proprieta div.style.top = val+'px';

    vorrei però che il movimento fosse più fluido, entri velocemente e deceleri fino alla posizione stabilita, potete darmi una mano
    codice:
    <script  type="text/javascript">
    	function open(){
    		function sposta(nP){
    			var obj = document.getElementById('panel');
    				//obj.style.top = '-80px';
    
    			//obj.style.top += 1 +'px';
    			var posTop = obj.style.top;
    			var t = posTop.split('px'); 
    			var tn = Number(t[0]); 
    			var nP = tn+20+"px";  alert(tn)
    			if(tn>=0){clearInterval(s)}
    			obj.style.top = nP;	
    		}
    		var obj = document.getElementById('panel');
    		obj.style.top = '-80px';
    		var nP = (nP!='undefined')?nP:0; 
    		var s = setInterval(function(){sposta(nP)},1000);
    		
    	}
    </script>
    
    <style type="text/css">
    #panel{
    	position: absolute;
    	/*top: -80px;*/
    	
    
    }
    </style>
    
    </head>
    
    <body>
    <script type="text/javascript">
    window.onload = function(){
    	open();
    }
    </script>
    <div id="panel">
    dignissim lectus, nec dapibus nibh lorem sodales risus. Donec ac ipsum. Praesent ac lorem. Nunc velit erat, pellentesque ac, mattis ac, convallis vel, purus. Aliquam sit amet justo a augue congue commodo.
    </div>

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    (studia e) applica le easing equations di penner
    ciao

  3. #3
    Giusto per il gusto di provarci

    Codice PHP:
    <style type="text/css">
    #panel{
        
    positionabsolute;
        
    /*top: -80px;*/
        
    width200px;
        
    height200pxbackground-color:#BBBBBB;

    }
    </
    style>
    <
    script  type="text/javascript">
        function 
    open(){
            var 
    speed0;
            var 
    stop200;
            var  
    selfdocument.getElementById('panel');
            function 
    sposta(){
                var 
    oldTopself.style.top.split('px')[0];
                if(
    oldTop<stop){
                    
    speed speed+Math.ceil((stop oldTop)/10) ;
                    
    self.style.top speed +'px';
                }
                else{
                    
    clearInterval(s);
                }
            }
            
    self.style.top = -80+'px';
            var 
    setInterval(sposta,50);
            
        }
    window.onload = function(){
        
    open();
    }
    </script> 


    Ps.

    Mi fa impazzire AS
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.