在网上查了一下,Jquery动画在IE下出现抖动,是因为浏览器解析该页面并没有采用标准模式,而Jquery动画必须是在标准模式之下,也就是strict mode。# u: n' |" M8 E9 |8 x6 a
如果不在HTML前制定DOCTYPE,那么IE会使用怪癖模式,也就是Quirks Mode解析该页面。从科学地角度讲,我们还是应该制定为strict mode的。但是难保你当初为了省事而忘记写了,结果项目越做越大了。5 o$ f5 P& ~- v0 a
而你又恰恰使用了Jquery,你可以选在再把制定为strict mode的这行代码
- d* S A& o' J! q<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/codefilter_code]6 g) R# `9 r/ ]/ Y
加上去,Jquery动画正常了,可许多页面布局又乱掉了。很显然得不偿失啊。# y& R' n# o: J, I7 e' ^
下面就是改写Jquery动画中的slideUp和slideDown,(我发现自己有写的让别人看不懂的能力,谁叫怪事太多了呢)。& ]; [$ B2 \2 W0 H3 u5 }2 J
(function($){
" R1 S0 n5 H/ b5 v( V5 ` var timer;% H( K# {4 z, z6 D; u7 K. }
$.fn.customSlide = function(options){
, E. Y; c! Y) B- c! n R1 U4 L3 Y var defaults = {' k9 K& q- L% I! l: M S+ ^; X" B
'flag' : 'down', //the flag using differing "SlideDown" and "SlideUp"7 h2 C' T- B' y8 k5 b
'delay' : 10, // the delay of the slide function
$ ]8 r, S5 |/ Z8 n6 M6 f( p 'distance' : 10 //the distance of the element's each step
% }3 a: U5 I$ u+ A( H) b};
3 c* h- `- X" u( Xvar options = $.extend(defaults, options);2 ^; `8 W# R& z
this.each(function(){/ W& J; T, ?/ R7 E- a8 f) R, u' T
$(this).css('overflow', 'hidden');- \0 M' M" s/ ]$ H
clearInterval(timer);2 W0 C/ u1 N! y2 S
var initHeight = $(this).height();
7 N1 ~! N. i+ Y# L- N* X if(typeof $(this).data('initHeight') == 'undefined'){$(this).data('initHeight', initHeight);}# D4 j2 O) B( ~3 R( z# V! @
if(typeof $(this).data('initAction') == 'undefined'){$(this).data('initAction', true);} O. a2 u& A: u+ P4 P( e, f6 V/ A
if(options.flag == 'up'){) z K# u8 M0 D2 o8 T
timer = setInterval($(this).slide(parseInt('-' + options.distance)), options.delay);/ |; `: i' a! {7 s: H* W, ]
}else{
* X# g9 u" l2 ]: ^& }* ] timer = setInterval($(this).slide(options.distance), options.delay);
1 h4 `, n! a$ @% H }, I1 l* Y( S) J6 P( t6 A
});- j5 [2 z/ c; A2 Z3 K' m
};
/ i4 X; l4 S, i$ x$ E $.fn.slide = function(distance){- z- j; c) `8 T& z$ w" J; m6 w0 x* [
var element = this;
8 k$ E" K5 z0 y+ `* M# K9 M return function(){: C: D' ]5 R( z: _$ O; \
var height = element.height() + distance;
) z" t7 _0 B% i) p5 o6 ] if(typeof element.data('initAction') != 'undefined' && element.data('initAction')){
. B2 P* ]4 N/ Q0 U S2 y height = 1;
/ S& m# ]- G) x7 ]* C element.height(height);5 P( F8 P4 f7 ?1 ^- G+ _
element.show();# `- B' L z& R1 E6 Z2 J
element.data('initAction', false);) q: K, h; V5 f& h+ H0 L
}; |# ~; Z8 |7 U4 Y) ~) t/ |8 ~
if(height < 0){
' w! R" w# e" Q+ Y" g8 O& V element.height(0);1 B) H4 q; b o6 O3 c
element.hide();
0 N% c; ~% v% V4 ?if(typeof element.data('initAction') != 'undefined' && !element.data('initAction')){
, p2 p( m1 I$ L+ \+ K5 R5 | element.data('initAction', true);5 s( p4 t2 ~: A- W3 p( R
}6 I# \6 f+ F3 x: b5 K: h7 d
clearInterval(timer);0 {% P) z; g7 H
}else if(height > element.data('initHeight')){# }9 ]% u0 ]8 W( e T2 y
element.height(element.data('initHeight'));
, \$ I4 }' G1 K; |. UclearInterval(timer);+ Q7 x9 U) H( p+ n6 r: p5 l
}else{
% j/ o5 r% S3 b% U element.height(height); z: Z7 y+ h1 K" k: m- `6 _
}
. w. S: ?, E( l1 h};
9 P9 f4 z/ y, l1 g3 _% w6 a! S/ ] }- R! W! M6 ?7 T1 |# k* v
})(jQuery)6 b. l: O# u* b" x. q c
# a. h% Q8 g7 q7 T K- S3 l! T1 g
i5 ~: I- l3 @
; `. n7 z1 I* q5 C* k' y
' N1 d( V. G7 B) x感谢溯游分享!!!$ ~& s( F% G4 V2 @
; Z& }" a; c! q G- F4 q* |
+ U" B% m2 A7 t" T# l( F" e4 A9 g- q6 F* P( H3 C
' l: T' j! S. e" n
& ?+ l. _$ }6 z1 c- m6 F |
|