I have a div which I want it to slide from the right of the screen 1 or 2 seconds after the page finished loading.
It seems I cannot achieve this without using the click function. How can I make this work?
I have a div which I want it to slide from the right of the screen 1 or 2 seconds after the page finished loading.
It seems I cannot achieve this without using the click function. How can I make this work?
Add a callback function for page load:
<body onload="script();">
then add the function:
function script(){
     setTimeout(function(){
         document.getElementById('elementToMove').style.left = '1000px'; // new left position is 1000px in this example
     }, 2000); // 2000 = 2 seconds after page load
}
And don't forget to add CSS3 transition to create the sliding effect
#elementToMove{
  -webkit-transition: left 1s ease;
  transition: left 1s ease;
}
 
    
    This is possible using only CSS animations. Here's an example:
.slidein {
    float:right;
    animation-duration: 5s;
    animation-name: slidein;
}
@keyframes slidein {
    from {
        margin-right: -30%;
    }
    to {
        margin-right: 0%;
    }
}
 
    
    