-
Notifications
You must be signed in to change notification settings - Fork 2
/
jquery.scorenotify.js
68 lines (59 loc) · 1.43 KB
/
jquery.scorenotify.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
* jQuery 'ScoreNotify' plugin 0.1
*
* http://github.com/paulasmuth/jquery.scorenotify
*
* Copyright (c) 2011 Paul Asmuth
*
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*/
(function($){
$.fn.scoreNotify = function(opts){
var default_label_func = function(_opts){
var n = parseInt(_opts.value);
return ((n > 0) ? ('+'+n) : n);
};
if(!opts.label_func){ opts.label_func=default_label_func; }
if(!opts.offset_x){ opts.offset_x=0; }
if(!opts.offset_y){ opts.offset_y=0; }
if(!opts.delta_y){ opts.delta_y=3; }
$('body').prepend(
opts.elem = $('<div></div>').css({
textAlign: 'center',
position: 'fixed',
float: 'left',
display: 'none'
})
);
opts.elem.html(
opts.label_func(opts)
).addClass(
opts.add_class || 'score_notify'
);
opts.offset_x += (
this.offset().left +
parseInt(this.width()/2) -
parseInt(opts.elem.width()/2)
);
opts.offset_y += (
this.offset().top -
opts.elem.height()
);
opts.target_y = (
opts.offset_y -
(opts.elem.height()*opts.delta_y)
);
opts.elem.css({
left: opts.offset_x,
top: opts.offset_y,
display: 'block',
opacity: 1
}).animate({
top: opts.target_y,
opacity: 0
}, 300, function(){
$(this).remove();
});
};
})(jQuery);