Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a div shake on page load?

Is there anyway to make a div box shake on page load? Like maybe just once or twice?

Update: At this URL I have it still not working on page load, what am I doing wrong? http://tinyurl.com/79azbav

I think I'm stuck at the onpage load; that failure can be seen here: Get onpage to work correctly

I've also tried initiating the animation with my already implemented body onLoad:

<body onLoad="document.emvForm.EMAIL_FIELD.focus(); document.ready.entertext.shake();" >

But still failing like a champ.

like image 887
fred randall Avatar asked Nov 07 '11 19:11

fred randall


People also ask

How do you shake text in HTML?

CSS Code: In this section first we will design the text with some basic CSS and use @keyframes animation and then use the transitionX() function to produce the shaking effect when we hover over the text.

How do you shake an image in HTML?

Simply replace . shake:hover with .

How do you shake a button in CSS?

CSS Code: In this section, first we will design the button using CSS basic properties, then to create the shake effect or animation we will use the @keyframes rule, we will use the translateX() and rotate() functions to reposition the button element on x axis the create the desired effect when we hover over it.


1 Answers

Try something like this:

EDIT:
Changed Shake() to shake() for consistency with jQuery conventions.

jQuery.fn.shake = function() {
    this.each(function(i) {
        $(this).css({ "position": "relative" });
        for (var x = 1; x <= 3; x++) {
            $(this).animate({ left: -25 }, 10).animate({ left: 0 }, 50).animate({ left: 25 }, 10).animate({ left: 0 }, 50);
        }
    });
    return this;
} 

EDIT:
In my example the left position is set to 25, but you can reduce this for a more subtle effect or increase it for a more pronounced effect.

Using the shake function:

$("#div").shake();

Here's a jsFiddle that demonstrates it: http://jsfiddle.net/JppPG/3/

like image 166
James Johnson Avatar answered Oct 07 '22 15:10

James Johnson