在网上查了一下,Jquery动画在IE下出现抖动,是因为浏览器解析该页面并没有采用标准模式,而Jquery动画必须是在标准模式之下,也就是strict mode。- r- A( k: n7 \8 @3 z* G/ [
如果不在HTML前制定DOCTYPE,那么IE会使用怪癖模式,也就是Quirks Mode解析该页面。从科学地角度讲,我们还是应该制定为strict mode的。但是难保你当初为了省事而忘记写了,结果项目越做越大了。
$ Y- K8 A. g" x而你又恰恰使用了Jquery,你可以选在再把制定为strict mode的这行代码9 d% u& u3 R, i; F- W' N8 K8 {% v
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/codefilter_code]. x5 w- w/ A. C* N5 j. a/ U* T% G
加上去,Jquery动画正常了,可许多页面布局又乱掉了。很显然得不偿失啊。
1 }; E8 s7 m( m/ ?, J+ h1 S下面就是改写Jquery动画中的slideUp和slideDown,(我发现自己有写的让别人看不懂的能力,谁叫怪事太多了呢)。
, }6 O0 q+ Y8 T& u# B \; V$ y2 `(function($){
5 U9 ?: z" b. G var timer;0 z: B" n. G- W. v& Z W, b4 _
$.fn.customSlide = function(options){
. U0 f) \% _2 t5 }* g, F var defaults = {
$ T8 N' Q2 L4 V) t2 t, w 'flag' : 'down', //the flag using differing "SlideDown" and "SlideUp"
( R) @# g5 ~' L3 S' \ 'delay' : 10, // the delay of the slide function+ {( }8 {6 e3 V
'distance' : 10 //the distance of the element's each step
, ~* {4 H- H* {) q1 O* y: P};# ?% Q' g0 A, j1 @ B1 }
var options = $.extend(defaults, options);5 W% H$ W q7 R8 L7 G
this.each(function(){
/ Y7 t) |! K, ?" T $(this).css('overflow', 'hidden');/ z/ ^3 Y& ^& U; ]2 H$ b
clearInterval(timer);
; k6 E5 |6 p @1 O var initHeight = $(this).height();( H' g7 \" f, b- }
if(typeof $(this).data('initHeight') == 'undefined'){$(this).data('initHeight', initHeight);}- n/ X8 u/ f2 Q
if(typeof $(this).data('initAction') == 'undefined'){$(this).data('initAction', true);}- J. s8 A( A7 ]5 W) n G9 o
if(options.flag == 'up'){
& V- Z* q% k0 A5 L' H3 G9 dtimer = setInterval($(this).slide(parseInt('-' + options.distance)), options.delay);1 h: a$ R" U" c' l* O
}else{) p5 X G$ _4 b1 i7 t' T% v
timer = setInterval($(this).slide(options.distance), options.delay);9 }4 C; h% c7 q. n0 E
}
" S: a6 F* ~2 S Y/ U$ L" F6 C});0 W1 Z7 g. I1 m! \8 u
};
) m. d( q: m# w" I: V V% n $.fn.slide = function(distance){; h6 }; [' {# {1 o0 ]
var element = this; ?6 Z c2 d2 o+ [. y% q
return function(){
: i: [1 R$ u m var height = element.height() + distance;
4 x: {+ X1 e; b" M2 E8 y) L if(typeof element.data('initAction') != 'undefined' && element.data('initAction')){
* }3 A6 B- l7 x: V: Z( V' z height = 1;" {/ R/ `& E9 Y6 X) g# [7 s p
element.height(height);
% I' N1 [5 j- K% D7 D! Delement.show();
6 d( R& J! |2 E. H2 {( Z0 @element.data('initAction', false);) C8 Z( \( y6 i6 {& J
}
/ v% r3 R; W/ R' z% ~6 F+ z$ Z if(height < 0){9 F) t, V* t) o- `
element.height(0);+ i4 \, h" p) t; b; d8 r
element.hide();
" r% W* h; s$ R b" ?5 O7 vif(typeof element.data('initAction') != 'undefined' && !element.data('initAction')){/ j, ^% ?9 q! ?) U+ _- w
element.data('initAction', true);8 c9 W! J/ [3 W2 ?; p
}" O- e+ Q$ M* }: @% p5 @
clearInterval(timer);
A0 Z" B3 ~) H2 K+ ^6 B }else if(height > element.data('initHeight')){1 x, d1 c# n' I$ n( C% |* e3 X
element.height(element.data('initHeight'));( E9 |+ L5 n8 F% R- W5 b
clearInterval(timer);
" z/ L2 r G: |8 Q }else{" l1 l$ J/ Z* E5 {& J8 A
element.height(height);: Z/ s: a6 _. i4 H$ o7 `7 P
}
4 \4 U& Q& \, f, O' h};
2 b* S6 e6 u6 C" c" E! X5 x* ?- Q( {6 v m }9 g, f$ _- d6 N8 n2 {" ^6 h2 b! a
})(jQuery)" {: p* p7 v% }" ]$ v1 w
5 f- j. \& @& _: E
0 B" ?" X7 W( W3 Z+ |9 J: R$ j' F( }3 b/ {- Y" A& q
% w& g- e, M8 J9 Z
感谢溯游分享!!!
% L* u, I' o! s7 q) i- O6 {$ E( {! r( |0 d5 _! _7 O
; i& | k8 n, c! \% g1 ]$ B% x, x. c# Q
& V' k1 L: H% |: h: a8 ?( {) N) w
: T+ ~7 C, s; `! u' e4 s |
|