在网上查了一下,Jquery动画在IE下出现抖动,是因为浏览器解析该页面并没有采用标准模式,而Jquery动画必须是在标准模式之下,也就是strict mode。
) Y g5 @7 Z: _如果不在HTML前制定DOCTYPE,那么IE会使用怪癖模式,也就是Quirks Mode解析该页面。从科学地角度讲,我们还是应该制定为strict mode的。但是难保你当初为了省事而忘记写了,结果项目越做越大了。
4 y, F, Q0 B! d/ u( d9 [8 l而你又恰恰使用了Jquery,你可以选在再把制定为strict mode的这行代码+ K9 i) K. p1 h0 h) \0 H2 u: X% y
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/codefilter_code], x- r, ~. D& T
加上去,Jquery动画正常了,可许多页面布局又乱掉了。很显然得不偿失啊。0 K0 k6 O* W1 ]) @+ y! i/ P* M
下面就是改写Jquery动画中的slideUp和slideDown,(我发现自己有写的让别人看不懂的能力,谁叫怪事太多了呢)。
! R* v1 m. n9 G: z f(function($){
6 T6 O8 D2 m7 \5 N% W2 o var timer;$ |/ w: Y3 |: i2 t7 P
$.fn.customSlide = function(options){ w4 v8 d8 p. ~5 l
var defaults = {/ X- |" t; `3 {% O, r# O8 q+ C" }5 Q
'flag' : 'down', //the flag using differing "SlideDown" and "SlideUp"3 }; r( M6 S U9 g, W) F) P
'delay' : 10, // the delay of the slide function4 I5 ]; I; K& G/ U4 J
'distance' : 10 //the distance of the element's each step* \* ]' m) p" ? Q( F
};
8 {5 c E V. ?+ E! Qvar options = $.extend(defaults, options);
; g7 W# R0 o$ h% M) W& Gthis.each(function(){
: k% L3 f" L9 @3 i( i $(this).css('overflow', 'hidden');
8 _: @! k& g7 q: X! B- |# _ clearInterval(timer);: F0 b, x8 a0 D; q* I# W7 t
var initHeight = $(this).height();
; ^) [ S/ {' I, N9 x, C$ \ if(typeof $(this).data('initHeight') == 'undefined'){$(this).data('initHeight', initHeight);}; j) `" [! p9 R5 E& p0 U p
if(typeof $(this).data('initAction') == 'undefined'){$(this).data('initAction', true);}
4 m, j# r2 ^& ^' y) P- G# T: E if(options.flag == 'up'){: i+ ?3 z5 {( l+ K+ o2 ?
timer = setInterval($(this).slide(parseInt('-' + options.distance)), options.delay);
+ {5 [) ^ R! y. B }else{/ f' R( ]1 `' I3 S+ i5 f
timer = setInterval($(this).slide(options.distance), options.delay);
( {7 `1 Y/ C; {, S' W; } }( o6 u, e5 R5 f+ ^1 I
});- ^# {9 r `+ D* ^1 c! v
};
3 U( A# q! z$ v |2 w" g9 _ $.fn.slide = function(distance){9 b) T9 w8 ~% W- t
var element = this;* k" a# a+ P9 a/ |4 z3 v; p
return function(){( q6 S" R+ u2 i# l, l1 y
var height = element.height() + distance;6 D4 O; C$ x. ?, {% ~! s
if(typeof element.data('initAction') != 'undefined' && element.data('initAction')){
3 N% ]4 C0 h0 D8 r height = 1;# N y K/ L2 M% {3 p, q
element.height(height);; D2 ?/ Z) z! K7 r6 S
element.show();. e4 ?* |$ w5 x; k0 k9 b+ |5 u$ v
element.data('initAction', false);6 G8 _3 S* D, u' f2 y4 U
}
. B$ o* a1 h1 u, L7 f: r if(height < 0){
$ ?; b& `4 A' x: |" k element.height(0);6 ~. Y9 E5 u% C' u. J2 J- m' @
element.hide();
, [* J/ g# j" z2 X8 m( \2 W1 oif(typeof element.data('initAction') != 'undefined' && !element.data('initAction')){7 d$ p, Y& q. ^5 p6 p
element.data('initAction', true);
^8 u: r* x" J: o }
+ L$ p$ n8 Q6 \8 \" v/ r& ZclearInterval(timer);) ^7 X# Z( V& P4 L
}else if(height > element.data('initHeight')){7 e; I, T9 f1 |$ t: z( k
element.height(element.data('initHeight'));0 ]/ G3 y9 ?1 Q& A% z6 o! n" d
clearInterval(timer);$ J2 K! I4 y5 f8 i, E: ?6 H" K9 i3 e9 n
}else{9 L- |; G; Q+ F4 _* |5 z
element.height(height);
5 V' c0 f. l" Y' ? }+ ~1 h1 n6 A4 V, H2 Q) N
};0 @. G1 S$ c5 O" N+ b5 ?# `
}2 E. _3 T( n* Y/ z8 `/ E$ _9 Q! O
})(jQuery)8 F% B( B7 U8 e+ H9 i5 Z
7 [6 I; M& Y+ m4 H0 r4 D9 f. @: C K! E3 D, N9 C) g
# @ s0 t) a: h$ ]8 ~0 S
6 `8 ^# X @# D1 V感谢溯游分享!!!+ G% O# e3 ~5 v, o' L2 {' B
, }, y) ~0 L4 L/ O& V. T
8 f* _# o: H1 C
$ L6 `* G2 s1 [+ H
3 N0 \% J3 W% X# |! y, ~( }7 p
- A5 n5 H9 t" t: v8 n |
|