Created
January 14, 2013 22:50
-
-
Save raphaelbastide/4534284 to your computer and use it in GitHub Desktop.
RVB vibrations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RVB vibrations effect for text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { background-color: #fff; font-family:arial; font-size:50px;} | |
#box{position:relative; margin:80px 0 0 80px;} | |
#box p{position:absolute; top:0; left:0px; opacity:.333; cursor:crosshair; letter-spacing:1px; text-transform:uppercase; font-weight:bold;} | |
.main{opacity:1;} | |
.R{color:#FF0000;} | |
.V{color:#00FF00;} | |
.B{color:#0000FF;} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<link rel="stylesheet" media="screen" href="http://openfontlibrary.org/face/terminal-grotesque" rel="stylesheet" type="text/css"/> | |
<div id="box"> | |
<p class="main">Over Me</p> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".main").clone().removeClass('main').addClass('B').prependTo("#box"); | |
$(".main").clone().removeClass('main').addClass('R').prependTo("#box"); | |
$(".main").clone().removeClass('main').addClass('V').prependTo("#box"); | |
$(".main").hide(); | |
jQuery.fn.vibrate = function (conf) { | |
var config = jQuery.extend({ | |
speed: 30, | |
duration: 1000, | |
spread: 5 | |
}, 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({ | |
left: leftPos + 'px', | |
top: topPos + 'px', | |
WebkitTransform: 'rotate(' + rotate + 'deg)' // cheers to [email protected] for the rotation-idea | |
}); | |
}; | |
var doVibration = function () { | |
var vibrationInterval = setInterval(vibrate, config.speed); | |
var stopVibration = function () { | |
clearInterval(vibrationInterval); | |
t.css({ | |
left: '0', | |
top: '0', | |
WebkitTransform: 'rotate(0deg)' | |
}); | |
}; | |
setTimeout(stopVibration, config.duration); | |
}; | |
doVibration(); | |
}); | |
}; | |
$('#box').hover(function() {$('#box p').vibrate();}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment