在网上查了一下,Jquery动画在IE下出现抖动,是因为浏览器解析该页面并没有采用标准模式,而Jquery动画必须是在标准模式之下,也就是strict mode。' v- }# |3 }& ]+ Y$ r- L) f
如果不在HTML前制定DOCTYPE,那么IE会使用怪癖模式,也就是Quirks Mode解析该页面。从科学地角度讲,我们还是应该制定为strict mode的。但是难保你当初为了省事而忘记写了,结果项目越做越大了。
/ j6 y' g/ C6 E. S, c' v9 y而你又恰恰使用了Jquery,你可以选在再把制定为strict mode的这行代码
4 H. R- g0 O. {+ f$ I. ~<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/codefilter_code]/ t% B6 B, x& N1 Q8 e6 d4 r( Y
加上去,Jquery动画正常了,可许多页面布局又乱掉了。很显然得不偿失啊。
" l& t1 q. W7 d, x6 E4 I下面就是改写Jquery动画中的slideUp和slideDown,(我发现自己有写的让别人看不懂的能力,谁叫怪事太多了呢)。
5 {4 ?/ O9 ~$ r( J2 ~- n$ c- B4 D(function($){
J5 n. y6 h: c( ^ var timer;8 s. u# ~7 @7 \; V; B
$.fn.customSlide = function(options){
( u/ @- `3 T. r4 x3 Q var defaults = {
4 k+ k( d" Q, `. j# Y 'flag' : 'down', //the flag using differing "SlideDown" and "SlideUp"
; Q: R& W; o( l, p 'delay' : 10, // the delay of the slide function0 w# H5 m/ t8 }. m1 Z3 @0 S
'distance' : 10 //the distance of the element's each step
' r5 A2 t) n0 o$ `9 c0 ]+ ?+ c0 R};3 p) ]# J* Q+ A; q# y g
var options = $.extend(defaults, options);/ i/ d: A5 i. t. u
this.each(function(){0 q- P0 x2 F) d( Y2 j, h
$(this).css('overflow', 'hidden');! G+ @, k" v$ D; }3 l3 i1 G: L
clearInterval(timer);
2 q0 v2 ~0 x+ F9 R: c9 P' W2 I Z) Q var initHeight = $(this).height();4 m$ R9 Q! P7 X; ~
if(typeof $(this).data('initHeight') == 'undefined'){$(this).data('initHeight', initHeight);}
2 |8 X0 l, @4 I6 A if(typeof $(this).data('initAction') == 'undefined'){$(this).data('initAction', true);}
6 v; A" b) b( [3 W+ q if(options.flag == 'up'){' {: F4 D* B7 A4 ~/ O) Y
timer = setInterval($(this).slide(parseInt('-' + options.distance)), options.delay);% w) u$ \0 T1 M Q
}else{
# g' d# K) K1 A6 X, e timer = setInterval($(this).slide(options.distance), options.delay);3 [4 J) L8 q5 N/ m8 {3 N
}7 g8 m" f% W8 V9 g
});7 L* X! ] D9 y* P. J- l
};4 Q6 A7 D( s/ i$ v8 Z2 j
$.fn.slide = function(distance){2 |+ C8 J) J! p! R
var element = this;) F+ w7 q- }3 U! K! b; x7 h
return function(){" I$ E1 z6 w( D! Z" e9 o- C1 H
var height = element.height() + distance;
4 u& z, h8 X8 w if(typeof element.data('initAction') != 'undefined' && element.data('initAction')){; t; k& R6 f) H0 p+ S6 c9 e$ N+ h9 J
height = 1;& Y% `+ \8 X- |( ^' a, F' Y4 i, @
element.height(height);/ J+ k2 x$ O- d
element.show();% [5 Z E& u& d6 D9 R% F4 G( R1 ~
element.data('initAction', false);
( v s' y/ t1 W) `, N6 f }
( Y9 @5 w& M0 ^ if(height < 0){- V3 n- l+ [6 N, J( m9 W0 K( o; T
element.height(0);% H+ O& K; d9 ~) Z
element.hide();! o2 T4 f3 i% Y8 `# b: t8 L# U
if(typeof element.data('initAction') != 'undefined' && !element.data('initAction')){
7 g0 [* K6 B8 J2 L) i/ Q element.data('initAction', true);' F% G! m1 e1 _9 |: b3 r( X
}
5 E7 m( C- d" b& t8 BclearInterval(timer);
/ M7 w; g7 T& ` }else if(height > element.data('initHeight')){
7 d' \6 P6 T1 f( |, W element.height(element.data('initHeight'));
9 z% V0 I. Q4 Q. Z& I) p9 EclearInterval(timer);& O! i4 h% z' |! _% K7 K
}else{
9 s! h% }1 U5 {/ C( f6 w) S element.height(height);
' `. z0 ]* {# c. L/ v }# v7 n+ Y* I+ a6 D6 v8 x+ q
};
: n8 U! h1 K8 i }3 C5 e% T# f, a* h3 x
})(jQuery)1 Y2 L( ^1 e" U
$ ?6 d9 r& v2 x" C! D9 A
6 |) @* h' J. M8 Z# V& `
0 M, E9 L: L) Z$ I, h6 E, {9 \2 a
% \. ^! C7 Z! e8 @2 f5 M5 |/ o. B) B
感谢溯游分享!!!+ B0 a) Q, e/ @) {+ F0 B/ j: w
' t) R# m; ]5 g9 v
2 G5 [* W% _) h) [
$ {- B! j" w! e% `( T/ x; \+ {
! }% Q: {( v/ z) z8 t. b4 R: S
|
|