<!DOCTYPE html PUBLIC "- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Writing jQuery Plugin Demo</title>
<style type="text/css">
body {
background-color: #000000 ;
font-family: verdana ;
}
h1 {
color: #FAFAFA ;
font-weight: 400 ;
}
div {
background-color: #000000 ;
background-image: url( "jquery_logo.jpg" ) ;
font-size: 1px ;
height: 86px ;
left: 300px ;
line-height: 200px ;
overflow: hidden ;
position: absolute ;
text-align: center ;
top: 300px ;
width: 241px ;
}
</style>
<script type="text/javascript" src="jquery-1.2.pack.js"></script>
<script type="text/javascript">
jQuery.fn.vibrate = function(){
this.each(
function( intI ){
var jNode = $( this );
var blnVibrate = false;
var intLeft = parseInt( jNode.css( "left" ) );
var intTop = parseInt( jNode.css( "top" ) );
var fnUpdatePosition = function(){
var intCurrentLeft = parseInt(
jNode.css( "left" )
);
var intCurrentTop = parseInt(
jNode.css( "top" )
);
if (blnVibrate){
if (Math.random() > .5){
if (intCurrentTop > intTop){
intCurrentTop = (intTop - 2);
} else {
intCurrentTop = (intTop + 2);
}
} else {
if (intCurrentLeft > intLeft){
intCurrentLeft = (intLeft - 2);
} else {
intCurrentLeft = (intLeft + 2);
}
}
setTimeout(
fnUpdatePosition,
60
);
} else {
intCurrentLeft = intLeft;
intCurrentTop = intTop;
}
jNode.css(
"top",
(intCurrentTop + "px")
);
jNode.css(
"left",
(intCurrentLeft + "px")
);
}
jNode.mouseover(
function(){
blnVibrate = true;
fnUpdatePosition();
}
);
jNode.mouseout(
function(){
blnVibrate = false;
}
);
}
);
return( this );
}
$(
function(){
$( "div" ).vibrate();
}
);
</script>
</head>
<body>
<h1>
jQuery Plugin Demo: Vibrate -
Shake It Like A Polaroid Picture
</h1>
<div>
jQuery - Write Less. Do More.
</div>
</body>
</html>