Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason it shakes constantly is that the plugin is set up to create an element that shakes intermittently.... for ever. The shake is produced with <strong><a href="https://developer.mozilla.org/en/DOM/window.setInterval" rel="nofollow noreferrer">setInterval</a></strong>. setInterval is also used to trigger the intermittent periods of shaking.</p> <p>Working from <strong><a href="http://andreaslagerkvist.com/jquery/vibrate/" rel="nofollow noreferrer">the plugin by Andreas Lagerkvist you linked to</a></strong>, just remove the never ending intermittent shakes by removing the setInterval() call to doVibration(). Then you can set how long you want it to vibrate on a hover (you don't want it to vibrate the <strong>entire</strong> time someone hovers... do you? that'd be annoying)</p> <p>Put what you want to vibrate in a div and trigger the vibration with a <strong><a href="http://api.jquery.com/hover/" rel="nofollow noreferrer">.hover()</a></strong>. The advantage of hover is that it vibrate on both mouseenter and mouseleave if the user stops their mouse over the div. </p> <pre><code>$('#jquery-vibrate-example').hover(function() {$(this).vibrate();}); </code></pre> <p>If you only want it to vibrate once just use <strong><a href="http://api.jquery.com/mouseenter/" rel="nofollow noreferrer">.mouseenter()</a></strong></p> <pre><code>$('#jquery-vibrate-example').mouseenter(function() {$(this).vibrate();}); </code></pre> <h2><strong><a href="http://jsfiddle.net/gkw8n/" rel="nofollow noreferrer">jsFiddle example</a></strong></h2> <p><br/></p> <p>When you call <code>.vibrate()</code> you can pass the speed, duration, and spread (I removed frequency) in as parts of an object literal to fine tune the vibration: <code>$(this).vibrate({"speed":100,"duration":800,"spread":5});</code> for example. The larger the <code>speed</code> the slower it shakes, since <code>speed</code> is used directly in the <code>setInterval()</code> of the shaking. The other two are self explanatory:</p> <pre><code>jQuery.fn.vibrate = function (conf) { var config = jQuery.extend({ speed: 30, duration: 1000, spread: 3 }, conf); return this.each(function () { var t = jQuery(this); var vibrate = function () { var topPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2); var leftPos = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2); var rotate = Math.floor(Math.random() * config.spread) - ((config.spread - 1) / 2); t.css({ position: 'relative', left: leftPos + 'px', top: topPos + 'px', WebkitTransform: 'rotate(' + rotate + 'deg)' // cheers to erik@birdy.nu for the rotation-idea }); }; var doVibration = function () { var vibrationInterval = setInterval(vibrate, config.speed); var stopVibration = function () { clearInterval(vibrationInterval); t.css({ position: 'static', WebkitTransform: 'rotate(0deg)' }); }; setTimeout(stopVibration, config.duration); }; doVibration(); }); }; </code></pre> <hr> <p><strong>Note:</strong> The plugin changes the positioning of your shaking item to <code>relative</code>... so you'll get funny results if you apply it to an originally <code>absolute</code>ly positioned element.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload