-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.forceredraw.js
executable file
·51 lines (43 loc) · 1.43 KB
/
jquery.forceredraw.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
/**
* Force Redraw
*
* Created by Pascal Beyeler (anvio.ch)
* Dual licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*
*/
/**
* Sometimes the browser just does not redraw the elements after a CSS change or whatever.
* This plugin allows you to force a redraw in your browser.
*
* @example $('#myelement').forceRedraw(); //works in most cases
* @example $('#myelement').forceRedraw(true); //use this one to force a redraw by changing the element's padding
* @desc force a browser redraw.
*
* @param brutal
* @return jQuery object
*
* @name $.fn.forceRedraw
* @cat Plugins/Browser
* @author Pascal Beyeler (anvio.ch)
*/
(function($) {
$.fn.forceRedraw = function(brutal) {
//this fix works for most browsers. it has the same effect as el.className = el.className.
$(this).addClass('forceRedraw').removeClass('forceRedraw');
//sometimes for absolute positioned elements the above fix does not work.
//there's still a "brutal" way to force a redraw by changing the padding.
if(brutal) {
var paddingLeft = $(this).css('padding-left');
var parsedPaddingLeft = parseInt(paddingLeft, 10);
$(this).css('padding-left', ++parsedPaddingLeft);
//give it some time to redraw
window.setTimeout($.proxy(function() {
//change it back
$(this).css('padding-left', paddingLeft);
}, this), 1);
}
return this;
}
})(jQuery);