Native js achieves jitter similar to pop-up window _ javascript skills

Source: Internet
Author: User
This article mainly introduces information about how native js achieves jitter similar to pop-up windows. we recommend it to you. if you need it, you can refer to the jitter window that you have previously created.

  
   Document  Script window. onload = function () {// Obtain the random number function getRandNumber (rmin, rmax) of 0--255 {var cha = rmax-rmin; var rand = Math. random (); return rmin + Math. round (cha * rand)} var placement = document. getElementById ('dv ') var oDv2 = document. getElementById ('dv2') // an array of values to be obtained for jitter var arr = []; // setInterval (function () {var arr2 = [getRandNumber (0,255 ), getRandNumber (0,255), getRandNumber (0,255)]; random. style. B AckgroundColor = "rgb (" + arr2 [0] + "," + arr2 [1] + "," + arr2 [2] + ")"}, 130) // Obtain the jitter value in the array for (var I = 20; I> 0; I-= 2) {arr. push (I,-I)} // shake the first box. onclick = function () {sb (lag, 'left', function () {sb (lag, 'top')} // The second box jitters oDv2.onclick = function () {sb (oDv2, 'left', function () {sb (oDv2, 'top')} // jitter function sb (obj, attr, fnEnd) {var timer = null; var num = 0; clearInterval (timer) timer = setInterval (function () {obj. Style [attr] = parseInt (getStyle (obj, attr) + arr [num] + 'px 'Num ++; if (num = arr. length) {clearInterval (timer) fnEnd & fnEnd () obj. innerHTML = 'I am + getStyle (obj, 'backgroundcolor') + 'color' // alert (1) },50)} function getStyle (obj, attr) {return obj. currentStyle? Obj. currentStyle [attr]: getComputedStyle (obj) [attr] }}; script  

Click me

Click me

Demo diagram:

The above is all the content of this article. I hope you will like it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.