Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7826559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T09:27:57+00:00 2026-06-02T09:27:57+00:00

I want the javascript code to show a div in slow motion. function showDiv(divID)

  • 0

I want the javascript code to show a div in slow motion.

function showDiv(divID)
{
       if(document.getElementById(divID).style.display=='none')
       {
           document.getElementById(divID).style.display='block';  
       }
}

Here div appears, but not in slow motion. Can anyone help ??
Thanks in advance

Dev..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T09:27:58+00:00Added an answer on June 2, 2026 at 9:27 am

    There is no need of jQuery in this atall , its just a basic I am using your function to explain how thats done.

       function showDiv(divID)
       {
           if(document.getElementById(divID).style.display=='none')
           {
               document.getElementById(divID).style.display='block';  
           }
    }
    

    What your function is doing is basically removing the whole Element from BOX Model ( the toggle of block and none removes the element totally from the BOX Model so it doesnt occupies any space or anything , this but may / may not cause some layout issues );

    Now to animate it in slow motion you need a timing function.

    a timing function is a simple mathematical function which gives the value of the property ( opacity in your case ) for a given time or depending on other parameters .

    Other then that you also need to use properties like opacity in order to fade it (Opacity is a CSS property that defines the transparency of an element and its childrens )

    So let us begin with a very basic show / hide using setTimeout Function in JS.

    function getValue(t,dir){
    
      if( dir > 0){
       return 0.5*t; /* Y = mx + c  */
      }else{
       return 1-(0.5*t);
      }
      /* 
        Here the slope of line m = 0.5.
        t is the time interval.
      */
    }
    
    
    function animator(divID){
          if(!(this instanceof animator)) return new animator(divID); /* Ignore this */
      var Node = document.getElementById(divID),
          start = new Date.getTime(), // The initiation.
          now = 0,
          dir = 1,
          visible = true;
      function step( ){
        now = new Date.getTime();
        var val = getValue( now - start,dir)
        Node.style.opacity = val;
        if( dir > 0 && val > 1 || dir < 0 && val < 0 ){
          visible = !(visible*1);
          // Optionally here u can call the block & none 
          if( dir < 0 ) { /* Hiding  and hidden*/
            Node.style.display = 'none'; // So if were repositioning using position:relative; it will         support after hide 
          }
          /* Our animation is finished lets end the continous calls */
          return;
        }
        setTimeout(step,100); // Each step is executated in 100seconds
      }
      this.animate = function(){
        Node.style.display = 'block';
        dir *= -1;
        start = new Date.getTime();
        setTimeout(step,100);
      } 
    }
    

    now you can simply call the function

      var magician = new animator('divName');
    

    then toggle its animation by

      magician.animate();
    

    Now playing with the timing function you can create whatever possibilities you want as in

      return t^2 / ( 2 *3.23423 );
    

    or even higher polynomial equations like

      return t^3+6t^2-38t+12;
    

    As you can see our function is very very basic but it explains the point of how to make animations using pure js . you can later on use CSS3 module for animation and trigger those classes with javascript 🙂

    Or perhaps write a cross browser polyfill using CSS3 where available ( it is faster ) , and JS if not 🙂 hope that helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using this HTML,CSS and Javascript code (in one document together if you want
I have a JavaScript function code where I want to alert. function msgalert(x,y) {
I have a JavaScript function code where I want to alert. function msg(x,y) {
instead of re-writing the same function, I want to optimise my code : <div
I want change following javascript code to jquery code, How is it? With done
I want to generate Javascript code from an existing Java project ( original question
i have this javascript code to which i want to add the jquery fade-in
I have a javascript code using which I want to accomplish the following .
I'm coding up a page where I only want to use raw JavaScript code
I want to find the RSA code in both Javascript and Java code. And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.