jquery Plugin jrumble Implement Web element jitter

Source: Internet
Author: User
Tags constant setinterval

Jrumble, it can make any element on the page jitter up, the use of this effect on your site will have a great chance to attract the user's attention. The effect of this plugin can be used on links, or Div, you can set the range of jitter, XY coordinates, jitter amplitude, and so on. Can be set to when the mouse moves up jitter or the default has been jitter, plug-in customization is still pretty high. PS: This plugin in IE, there are still some small problems

JQuery Jrumble is a way to use

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 In the <script type= "Text/javascript" src= "js/jquery-jrumble.js" ></script> <script type= "Text/javascript" > $ (document). Ready (function () {$ (' #demo1 '). Jrumble ({rangex:2, rangey:2, rangerot:1});   $ (' #demo2 '). jrumble ({rangex:10, rangey:10, rangerot:4});   $ (' #demo3 '). Jrumble ({rangex:4, rangey:0, rangerot:0});   $ (' #demo4 '). Jrumble ({rangex:0, rangey:0, rangerot:5});   $ (' #demo5 '). Jrumble ({rumblespeed:0});   $ (' #demo6 '). Jrumble ({rumblespeed:50});   $ (' #demo7 '). Jrumble ({rumblespeed:100});   $ (' #demo8 '). Jrumble ({rumblespeed:200});   $ (' #demo9 '). JrumbLe ({rumbleevent: ' hover '});   $ (' #demo10 '). Jrumble ({rumbleevent: ' click '});   $ (' #demo11 '). Jrumble ({rumbleevent: ' MouseDown '});   $ (' #demo12 '). Jrumble ({rumbleevent: ' constant '});   $ (' #demo13 '). Jrumble ({posx: ' Left ', posy: ' Top '});   $ (' #demo14 '). Jrumble ({posx: ' Right ', posy: ' Top '});   $ (' #demo15 '). Jrumble ({posx: ' Left ', posy: ' Bottom '});   $ (' #demo16 '). Jrumble ({posx: ' Right ', posy: ' Bottom '});   $ ('. View-source pre '). Hide (); $ ('. View-source a '). Toggle (function () {$ (this). Siblings (' pre '). Stop (False, true). Slidedown; $ (this). HTML (' Hide Source '); The function () {$ (this). Siblings (' pre '). Stop (False, true). Slideup; $ (this). html (' View Source ');}; }); </script>

Parameter configuration of jrumble

Option Default Description

Rangex 2 Set The horizontal rumble range (pixels)

Rangey 2 Set The vertical rumble range (pixels)

Rangerot 1 Set the rotation range (degrees)

Rumblespeed Set the speed/frequency in milliseconds of the rumble (lower number = faster)

Rumbleevent ' hover ' Set the event that triggers the rumble (' Hover ', ' click ', ' MouseDown ', ' constant ')

Posx ' left ' If using jrumble in a fixed or absolute positioned element, choose ' left ' or ' right ' to match your CSS

Posy ' top If using jrumble on a fixed or absolute positioned element, choose ' top ' or ' bottom ' to match your CSS

Jquery-jrumble.js Source

?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30-31 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 The 96 97 98 99 100 101 102 103 104 105 106 107 108 109 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140-1 41 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170-171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 /* jrumble v1.1-http://jackrugile.com/jrumble by Jack Rugile-http://jackrugile.com Copyright, Jack Rugile MIT Li cense-http://www.opensource.org/licenses/mit-license.php/&nbsp; (function ($) {$.fn.jrumble = function (options) {& nbsp Jrumble OPTIONS//---------------------------------var defaults = {rangex:2, rangey:2, Rangerot:1, rumblespeed:10 , rumbleevent: ' Hover ', posx: ' Left ', posy: ' Top '}; &nbsp; var opt = $.extend (defaults, options); &nbsp; Return This.each (function () {&nbsp;//VARIABLE declaration//---------------------------------$obj = $ (this); VA R Rumbleinterval; var rangex = Opt.rangex; var rangey = Opt.rangey; var Rangerot = Opt.rangerot; Rangex = rangex*2; Rangey = rangey*2; Rangerot = rangerot*2; var rumblespeed = opt.rumblespeed; var objposition = $obj. css (' position '); var objxrel = opt.posx; var objyrel = Opt.posy; var objxmove; var objymove; var Inlinechange; &nbsp;//SET POSITION relation if CHANGED//---------------------------------if (objXrel = = "Left" {objxmove = parseint ($obj. css (' left ');} if (Objxrel = = "Right") {Objxmove = parseint ($obj. css (' right '), 10); } if (Objyrel = = "Top") {Objymove = parseint ($obj. CSS (' top ');} if (Objyrel = = ' Bottom ') {Objymove = parseint ($obj. css (' Bottom '), 10); } &nbsp;//Rumbler function//---------------------------------function Rumbler (elem) {var randbool = math.random (); VA R randx = Math.floor (Math.random () * (rangex+1))-RANGEX/2; var RandY = Math.floor (Math.random () * (rangey+1))-RANGEY/2; var Randrot = Math.floor (Math.random () * (rangerot+1))-RANGEROT/2; &nbsp;/If INLINE, make inline-block for rotation//---------------------------------if (elem.css (' display ') = = ' Inlin E ') {Inlinechange = true; Elem.css (' Display ', ' Inline-block ')} &nbsp;//ensure MOVEMENT//----------------------------- ----if (randx = 0 &amp;&amp; rangex!== 0) {if (Randbool &lt;. 5) {randx = 1;} else {randx =-1;}} &nbsp; if (RandY = = = 0 &amp;&amp; rangey!== 0) {if (Randbool &lt;. 5) {RandY = 1; else {RandY =-1;}} &nbsp;//Rumble BASED on POSITION//---------------------------------if (objposition = = ' absolute ') {elem.css ({' Position ': ' absolute ', '-webkit-transform ': ' Rotate (' +randrot+ ' deg ') ', '-moz-transform ': ' Rotate (' +randrot+ ' deg ') ', '- O-transform ': ' Rotate (' +randrot+ ' deg) ', ' transform ': ' Rotate ' (' +randrot+ ' deg) '}); Elem.css (Objxrel, objxmove+randx+ ' px '); Elem.css (Objyrel, objymove+randy+ ' px '); } if (objposition = = ' fixed ') {elem.css ({' position ': ' fixed ', '-webkit-transform ': ' Rotate (' +randrot+ ' deg) ', '- Moz-transform ': ' Rotate (' +randrot+ ' deg) ', '-o-transform ': ' Rotate (' +randrot+ ' deg ') ', ' transform ': ' Rotate (' +randrot+ ' deg '}); Elem.css (Objxrel, objxmove+randx+ ' px '); Elem.css (Objyrel, objymove+randy+ ' px '); } if (objposition = = ' Static ' | | objposition = = ' relative ') {elem.css ({' position ': ' relative ', '-webkit-transform ': ' Rotate (' +randrot+ ' deg) ', '-moz-transform ': ' Rotate (' +randrot+ ' deg ') ', '-o-transform ': ' Rotate (' +randrot+ ' deg ') ', ' Transform ': ' Rotate (' +randrot+ ' deg) '}); Elem.css (Objxrel, randx+ ' px '); Elem.css (Objyrel, randy+ ' px '); }//End Rumbler function &nbsp;//EVENT TYPES (rumbleevent)//---------------------------------var resetrumblercss = {' position ': objposition, '-webkit-transform ': ' Rotate (0deg) ', '-moz-transform ': ' Rotate (0deg) ', '-o-transform ': ' Rotate (0deg) ', ' transform ': ' Rotate (0deg) '}; &nbsp; if (opt.rumbleevent = = ' hover ') {$obj. Hover (function () {var Rumblee = $ (this); rumbleinterval = SetInterval (funct Ion () {Rumbler (Rumblee);}, Rumblespeed); }, function () {var Rumblee = $ (this); Clearinterval (Rumbleinterval); Rumblee.css (RESETRUMBLERCSS); Rumblee.css (Objxrel , objxmove+ ' px '); Rumblee.css (Objyrel, objymove+ ' px '); if (Inlinechange = = True) {rumblee.css (' display ', ' inline ');} ); } &nbsp; if (opt.rumbleevent = = ' click ') {$obj. Toggle (function () {var Rumblee = $ (this); rumbleinterval = SetInterval (func tion () {Rumbler (Rumblee);}, Rumblespeed); }, function () {var Rumblee = $ (this); Clearinterval (Rumbleinterval); Rumblee.css (resETRUMBLERCSS); Rumblee.css (Objxrel, objxmove+ ' px '); Rumblee.css (Objyrel, objymove+ ' px '); if (Inlinechange = = True) {rumblee.css (' display ', ' inline ');}}); } &nbsp; if (opt.rumbleevent = = ' MouseDown ') {$obj. bind ({mousedown:function () {var Rumblee = $ (this); Rumbleinterval = s Etinterval (function () {Rumbler (Rumblee);}, Rumblespeed); }, Mouseup:function () {var Rumblee = $ (this); Clearinterval (Rumbleinterval); Rumblee.css (RESETRUMBLERCSS); rumblee.css (Objxrel, objxmove+ ' px '); Rumblee.css (Objyrel, objymove+ ' px '); if (Inlinechange = = True) {rumblee.css (' display ', ' inline ');}, Mouseout:function () {var Rumblee = $ (this); Clearinterva L (Rumbleinterval); Rumblee.css (RESETRUMBLERCSS); Rumblee.css (Objxrel, objxmove+ ' px '); Rumblee.css (Objyrel, objymove+ ' px '); if (Inlinechange = = True) {rumblee.css (' display ', ' inline ');} }); } &nbsp; if (opt.rumbleevent = = ' constant ') {var Rumblee = $ (this); rumbleinterval = SetInterval (function () {Rumbler (rumb Lee); }, Rumblespeed); } &nbsp;}); }; }) (Jquery);

Online Demo http://jackrugile.com/jrumble/#demos

SOURCE Download Http://jackrugile.com/jrumble/jquery.jrumble.1.3.zip

The above mentioned is the entire content of this article, I hope you can enjoy.

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.