jquery Plugin jrumble Implement page element jitter _jquery

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

<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 (500);
 $ (this). html (' Hide Source ');
 , function () {$ (this). Siblings (' pre '). Stop (False, True). Slideup (500);
 $ (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

/* 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 */function ($) {$.fn.jrumble = function (options) {//Jrum  BLE OPTIONS//---------------------------------var defaults = {rangex:2, rangey:2, Rangerot:1, Rumblespeed:

 Rumbleevent: ' Hover ', posx: ' Left ', posy: ' Top '};

 var opt = $.extend (defaults, options);  
  Return This.each (function () {//VARIABLE declaration//---------------------------------$obj = $ (this); 
  var 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; SET POSITION Relation IF CHANGED//---------------------------------if (Objxrel = = "Left") {Objxmove = parseint ($obj. css (' left '), 10);
  } if (Objxrel = = ' right ') {Objxmove = parseint ($obj. css (' right '), 10);
  } if (Objyrel = = "Top") {Objymove = parseint ($obj. CSS (' top '), 10);
  } if (Objyrel = = ' Bottom ') {Objymove = parseint ($obj. css (' bottom '), 10); }//Rumbler function//---------------------------------function Rumbler (elem) {var randbool = Math.rand
  Om ();
  var 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; 
   If INLINE, make inline-block for rotation//---------------------------------if (elem.css (' display ') = = ' INLINE ') {
   Inlinechange = true; Elem.css (' Display ', ' Inline-block ')}//ensure MOVEMENT//---------------------------------if (randx = 0 &
   amp;& Rangex!== 0) {if (Randbool < 5) {randx = 1;
  } else {randx =-1;
   } if (Randy = = 0 && rangey!== 0) {if (Randbool <. 5) {Randy = 1;
   else {RandY =-1; }//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-tra Nsform ': ' 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//EVENT TYPES (rumbleevent)//---------------------------------var Resetrumblerc SS = {' position ': objposition, '-webkit-transform ': ' Rotate (0deg) ', '-moz-transform ': ' Rotate (0deg) ', '-o-transform ': '
  
  Rotate (0deg) ', ' transform ': ' Rotate (0deg) '};
   if (opt.rumbleevent = = ' hover ') {$obj. Hover (function () {var Rumblee = $ (this);
   Rumbleinterval = setinterval (function () {Rumbler (Rumblee);}, Rumblespeed);
   The 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 ');
  }
   }
  ); } if (opt.rumbleevent = = ' clicK ') {$obj. Toggle (function () {var Rumblee = $ (this);
  Rumbleinterval = setinterval (function () {Rumbler (Rumblee);}, Rumblespeed);
   The 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 ');
  }
  });
   } if (opt.rumbleevent = = ' MouseDown ') {$obj. bind ({mousedown:function () {var Rumblee = $ (this);
   Rumbleinterval = setinterval (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);
   Clearinterval (Rumbleinterval);
   Rumblee.css (RESETRUMBLERCSS); RUmblee.css (Objxrel, objxmove+ ' px ');
   Rumblee.css (Objyrel, objymove+ ' px ');
   if (Inlinechange = = True) {rumblee.css (' display ', ' inline ');
  }
   }
  });
  } if (opt.rumbleevent = = ' constant ') {var Rumblee = $ (this);
  Rumbleinterval = setinterval (function () {Rumbler (Rumblee);}, Rumblespeed);
 }
  
 }); 
};

 }) (JQuery);

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

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.