Creating vibration on page load?

Is there any way to make the div tag load the page? Like once or twice?

Update: at this url, the page loading is still not working for me, what am I doing wrong? http://tinyurl.com/79azbav

I think I'm stuck on onpage loading; this failure can be seen here: Get onpage for proper operation

I also tried running the animation with the body onLoad already implemented:

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

But still a failure, like a champion.

+6
source share
2 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 it for a finer effect or increase it for a more pronounced effect.

Using the shake function:

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

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

+24
source

A little variation on @ James-Johnson is a great answer for ~ shaking elements located absolute . This function captures the current left position of the element and shakes it relative to this point. I went for less violent shaking, gas mark 10.

 jQuery.fn.shake = function () { this.each(function (i) { var currentLeft = parseInt($(this).css("left")); for (var x = 1; x <= 8; x++) { $(this).animate({ left: (currentLeft - 10) }, 10).animate({ left: currentLeft }, 50).animate({ left: (currentLeft + 10) }, 10).animate({ left: currentLeft }, 50); } }); return this; } 
+4
source

Source: https://habr.com/ru/post/900969/


All Articles