Home > Web Front-end > JS Tutorial > body text

Jquery UI vibration effect implementation principle and steps_jquery

WBOY
Release: 2016-05-16 17:42:26
Original
1149 people have browsed it

If you want to attract readers' attention to certain parts of your blog page, you can make these parts vibrate, such as ads. Today's article will introduce how to make elements in your page vibrate.

To achieve this purpose we need to use Jquery and Jquery UI.
First, let me create a shake block, which can be a picture or an ordinary dom element, such as div, span, etc., and name the element's id as shake. You can name it arbitrarily.

We use pictures as follows:

Copy code The code is as follows:

< ;img src="http://jqueryui.com/jquery-wp-content/themes/jquery/images/logo-jquery-ui.png" id="shake"/>

Jquery UI does not have a ready-made method to vibrate elements. We need to use the effect method to achieve it. The syntax is as follows:
Copy code Code As follows:

effect('shake', options, speed);

Parameter options (there are three parameters here):
·times: Specify the number of times the element shakes
•distance: Specify the vibration amplitude of the element
•Direction: Specify the vibration direction of the element
The following is the specific implementation method, set the vibration 3 times, and call the vibration every 500ms:
Copy code The code is as follows:

function interval() {
$('#shake').effect('shake', { times:3 }, 100);
}
$(document).ready(function() {
var shake = setInterval(interval, 500);
});


Here I imported the latest version.
The complete code is attached below
Copy the code The code is as follows:





<script> <br>function interval() { <br>$('#shake').effect('shake', { times:3 }, 100); <br>} <br>$(document ).ready(function() { <br>var shake = setInterval(interval, 500); <br>}); <br></script>

jQuery Shake Effect


jQuery Shake Effect











Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!