Recently someone asked me that, I want that vibrate effect which you can see in some site as an advertisement. In some site, advertisement comes with vibrate/shake effect so which highlight it or a way to direct attention to that advertisement banner.
So Today I am going to explain how to vibrate or shake an advertisement banner using jQuery.jQuery provide shake effect which we can use for our purpose.
First of all, Let’s create one div with id shake which is used as the element.shake effect moves an element horizontally or vertically using the argument passed in the effect call options.
1 2 3 | <div id="shake" style="width: 300px; height: 100px; background-color:#C91622;color:#fff;">CreativeDev |
Syntax
1 2 3 | effect('shake', options, speed); |
options: Here we have three options:
- times: specifies times an element be shake
- distance :specifies the distance between element’s positions
- direction: specifies the direction of the shaking effect (horizontal or vertical) speed:is a time length in milliseconds.
Let’s understand code using jQuery shake.Here I have called shake id 3 times in every 500 ms so its vibrate continuously.
1 2 3 4 5 6 7 8 | $('#shake').effect('shake', { times:3 }, 100); } $(document).ready(function() { }); |
Keep in mind: Don’t forget to load latest version of jquery to effect get work.
DEMO
Hope this post will helpful for you, waiting for your responses.Thanks for reading and feel free to share your thoughts! Don’t Forget to Follow us on Twitter or Subscribe us to Get the Latest Updates.