Search code examples
javascriptjqueryanimationtextsliding

How do I make text slide to the right upon page load?


I'm not fluent in javascript and I'm trying to edit this example at w3schools to make a simple headline within a div slide to the right smoothly (from out of view) upon page load. I just KNOW it has something to do with the code that is already here, but I'm having two problems.

  1. When I turn the box they are moving into a text headline and change the "div" selector into '.headline' (or whatever I've named it), clicking the button won't move it.

  2. If I figure that out, I still don't know how to make it work without the button.


Solution

  • Right now that code is invoked with a click handler, just remove the wrapper for that and execute it on page load:

    $(document).ready(function() {
        $(".header").animate({ //be sure to change the class of your element to "header"
            left:'250px',
            opacity:'0.5',
            height:'150px',
            width:'150px'
        });
    });
    

    Demo: http://jsfiddle.net/tymeJV/ZWtQw/1/