Skip to content

Instantly share code, notes, and snippets.

@tobynet
Created July 7, 2010 14:47
Show Gist options
  • Save tobynet/466787 to your computer and use it in GitHub Desktop.
Save tobynet/466787 to your computer and use it in GitHub Desktop.
web 1.0 jQuery plugin at 2010-04-01 aprilfool, originaled by sixapart
/*
* This program is distributed under the terms of the
* GNU General Public License, version 2.
*
*/
(function ($) {
/*
* cursorrat
*
* Usage:
* jQuery.cursorrat({
* path: '/images/',
* images: ['cur01.gif', 'cur02.gif', 'cur03.gif', 'cur04.gif']
* });
*
* css:
* span.rat {
* position: absolute;
* width: 16px;
* height: 16px;
* }
*
*/
$.cursorrat = function (options) {
var defaults = {
path: '/',
images: [],
duration: 20,
interval: 8
};
var opts = $.extend(defaults, options);
var $cursorrat = $('.cursorrat');
if (!$cursorrat.length) {
$('body').append('<div class="cursorrat"></div>');
var duration = new Array();
var msec = opts.duration;
$.each(opts.images, function (index, value) {
$('.cursorrat').prepend('<span id="rat' + index + '" class="rat"><img src="' + opts.path + value + '"></span>');
duration[index] = msec;
$(document).mousemove(function (e) {
$('#rat' + index).animate({
'left': e.pageX + 16,
'top': e.pageY
}, duration[index]);
});
msec += opts.interval;
});
}
};
/*
* blink
*
* Usage:
* jQuery('.blink').blink();
*
*/
$.fn.blink = function (options) {
var defaults = {
interval: 400
};
var opts = $.extend(defaults, options);
return this.each(function () {
var $obj = $(this);
setInterval(function () {
$obj.css('visibility', $obj.css('visibility') == 'visible' ? 'hidden' : 'visible');
}, opts.interval);
});
};
/*
* blink
*
* Usage:
* jQuery('.marquee').marquee();
* jQuery('.marquee').marquee({direction: 'right'});
* jQuery('.marquee3').marquee({behavior: 'alternate', scrollamount: 8});
*
* css:
* span.marquee {
* position: relative;
* width: 100px;
* }
*
*/
$.fn.marquee = function (options) {
var defaults = {
delay: 100,
behavior: 'scroll',
direction: 'left',
scrollamount: 6
};
var opts = $.extend(defaults, options);
return this.each(function () {
var $obj = $(this);
var width = $obj.parent().width() - $obj.width();
var start;
var position;
var offset = 0;
var sign;
switch (opts.direction) {
case 'right':
sign = 1;
start = 0;
break;
default:
// 'left'
sign = -1;
start = width;
}
position = start;
setInterval(function () {
$obj.css({
left: position + sign * offset
});
if (offset < width) {
offset += opts.scrollamount;
} else {
if (opts.behavior == 'alternate') {
sign *= -1;
if (sign == 1) {
start = 0;
} else {
start = width;
}
}
offset = 0;
position = start;
}
}, opts.delay);
});
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment