Gå til innhold

"gli inn/gli ut"-animasjon


Anbefalte innlegg

Videoannonse
Annonse

Om du vil kan du ta utgangspunkt i følgende, som funker i Opera 9.00 ihvertfall:

 

Skjult tekst: (Marker innholdet i feltet for å se teksten):

<html>
<head>
 <style>

 #wrapper {
     width: 600px;
     margin: 0 auto;
     background-color: #ffcccc;
 }

 #thingy {
     height: 0;
     overflow: hidden;
     background-color: #ccccff;
 }

 </style>
 <script type="text/javascript">

 var direction = 1;        // When starts hidden, otherwise -1
 var animationSteps = 50;  // Number of steps in animation
 var animationTime = 500;  // Total time in milliseconds
 var maxHeight = 100;      // Max height of thingy

 function showHide()
 {
     var element = document.getElementById( 'thingy' );
     var currentHeight = parseInt( element.style.pixelHeight );

     if (( direction > 0 && currentHeight == maxHeight )
         || ( direction < 0 && currentHeight == 0 ))
     {
         direction = -direction;
     }
     else
     {
         var newHeight = Math.round( currentHeight + direction * maxHeight / animationSteps );

         if ( newHeight < 0 )
         {
             newHeight = 0;
         }
         else if ( newHeight > maxHeight )
         {
             newHeight = maxHeight;
         }

         element.style.height = newHeight + 'px';
         setTimeout( 'showHide()', Math.round( animationTime / animationSteps ) );
     }
 }

 </script>
</head>
<body>

<div id="wrapper">

 <div id="thingy">
   <p>Thingy-innhold</p>
 </div>

 <h2>Hallo</h2>
 <p>Masse innehold. Masse innhold. Masse innhold. Masse innhold.</p>
 <p><input type="button" value="Klikk her!" onclick="showHide()"></p>

</div>

</body>
</html>

Endret av balletryne
Lenke til kommentar
  • 3 uker senere...
  • 3 uker senere...
Gjest Slettet-df17e
Om du vil kan du ta utgangspunkt i følgende, som funker i Opera 9.00 ihvertfall:

 

Skjult tekst: (Marker innholdet i feltet for å se teksten):

<html>
<head>
 <style>

 #wrapper {
     width: 600px;
     margin: 0 auto;
     background-color: #ffcccc;
 }

 #thingy {
     height: 0;
     overflow: hidden;
     background-color: #ccccff;
 }

 </style>
 <script type="text/javascript">

 var direction = 1;        // When starts hidden, otherwise -1
 var animationSteps = 50;  // Number of steps in animation
 var animationTime = 500;  // Total time in milliseconds
 var maxHeight = 100;      // Max height of thingy

 function showHide()
 {
     var element = document.getElementById( 'thingy' );
     var currentHeight = parseInt( element.style.pixelHeight );

     if (( direction > 0 && currentHeight == maxHeight )
         || ( direction < 0 && currentHeight == 0 ))
     {
         direction = -direction;
     }
     else
     {
         var newHeight = Math.round( currentHeight + direction * maxHeight / animationSteps );

         if ( newHeight < 0 )
         {
             newHeight = 0;
         }
         else if ( newHeight > maxHeight )
         {
             newHeight = maxHeight;
         }

         element.style.height = newHeight + 'px';
         setTimeout( 'showHide()', Math.round( animationTime / animationSteps ) );
     }
 }

 </script>
</head>
<body>

<div id="wrapper">

 <div id="thingy">
   <p>Thingy-innhold</p>
 </div>

 <h2>Hallo</h2>
 <p>Masse innehold. Masse innhold. Masse innhold. Masse innhold.</p>
 <p><input type="button" value="Klikk her!" onclick="showHide()"></p>

</div>

</body>
</html>

6480250[/snapback]

 

Den koden funker fint i Opera, men ikke i FF - noe tips til hvordan man fikkser det ? Er på utkikk etter et slikt script :)

Lenke til kommentar

Gjort en liten forandring på det nå. Funker nå i Opera of FireFox hos meg.

 

Skjult tekst: (Marker innholdet i feltet for å se teksten):

<html>
<head>
<style>

#wrapper {
    width: 600px;
    margin: 0 auto;
    background-color: #ffcccc;
}

#thingy {
    height: 0;
    overflow: hidden;
    background-color: #ccccff;
}

</style>
<script type="text/javascript">

var direction = 1;        // When starts hidden, otherwise -1
var animationSteps = 50;  // Number of steps in animation
var animationTime = 500;  // Total time in milliseconds
var maxHeight = 100;      // Max height of thingy

function showHide()
{
    var element = document.getElementById( 'thingy' );

    if ( !element.style.height )
    {
        element.style.height = '0px';
    }

    var currentHeight = parseInt( element.style.height );

    if (( direction > 0 && currentHeight == maxHeight )
        || ( direction < 0 && currentHeight == 0 ))
    {
        direction = -direction;
    }
    else
    {
        var newHeight = Math.round( currentHeight + direction * maxHeight / animationSteps );

        if ( newHeight < 0 )
        {
            newHeight = 0;
        }
        else if ( newHeight > maxHeight )
        {
            newHeight = maxHeight;
        }

        element.style.height = newHeight + 'px';
        setTimeout( 'showHide()', Math.round( animationTime / animationSteps ) );
    }
}

</script>
</head>
<body>

<div id="wrapper">

<div id="thingy">
  <p>Thingy-innhold</p>
</div>

<h2>Hallo</h2>
<p>Masse innehold. Masse innhold. Masse innhold. Masse innhold.</p>
<p><input type="button" value="Klikk her!" onclick="showHide()"></p>

</div>

</body>
</html>

Endret av balletryne
Lenke til kommentar

Opprett en konto eller logg inn for å kommentere

Du må være et medlem for å kunne skrive en kommentar

Opprett konto

Det er enkelt å melde seg inn for å starte en ny konto!

Start en konto

Logg inn

Har du allerede en konto? Logg inn her.

Logg inn nå
  • Hvem er aktive   0 medlemmer

    • Ingen innloggede medlemmer aktive
×
×
  • Opprett ny...