在网上查了一下,Jquery动画在IE下出现抖动,是因为浏览器解析该页面并没有采用标准模式,而Jquery动画必须是在标准模式之下,也就是strict mode。* s7 W$ a6 p8 W+ M p0 b, @" |, N
如果不在HTML前制定DOCTYPE,那么IE会使用怪癖模式,也就是Quirks Mode解析该页面。从科学地角度讲,我们还是应该制定为strict mode的。但是难保你当初为了省事而忘记写了,结果项目越做越大了。
# q6 }8 A) Z! O3 w而你又恰恰使用了Jquery,你可以选在再把制定为strict mode的这行代码
: {" R, ^9 f% k3 c; k) f<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/codefilter_code]! N2 x$ z8 J o9 A
加上去,Jquery动画正常了,可许多页面布局又乱掉了。很显然得不偿失啊。
. B) ^. Y: A; K2 G& u8 a- k下面就是改写Jquery动画中的slideUp和slideDown,(我发现自己有写的让别人看不懂的能力,谁叫怪事太多了呢)。% A( `4 _" O8 ~; v
(function($){
+ u8 v9 S# S7 D- E var timer;- k- y% @3 r$ w% Y# E9 Z# i/ a. |- u; ~! |
$.fn.customSlide = function(options){
0 `5 y3 W% {2 k( r var defaults = {% M; E {$ Q( A( H6 @
'flag' : 'down', //the flag using differing "SlideDown" and "SlideUp"
1 Y' G9 X0 P5 Q3 f @1 O$ u1 \0 Y 'delay' : 10, // the delay of the slide function
+ p! k0 ^7 L3 W8 { 'distance' : 10 //the distance of the element's each step
3 @( o( \- ?" U) B: _, X};# P8 j1 l8 g9 l
var options = $.extend(defaults, options);
2 u4 R0 ?/ } L# `# Lthis.each(function(){ u6 Z' c( _2 Z
$(this).css('overflow', 'hidden');
" p$ Z+ g! s, v: T clearInterval(timer);
5 U5 o% p" A/ V' D( T6 f$ J$ J6 e var initHeight = $(this).height();, g# n6 }) `% F, z
if(typeof $(this).data('initHeight') == 'undefined'){$(this).data('initHeight', initHeight);}
+ V; O9 \5 o! F# n. B if(typeof $(this).data('initAction') == 'undefined'){$(this).data('initAction', true);}6 P/ G* \& p( p" @& W
if(options.flag == 'up'){0 S8 [6 U; W! Q- w( @. i' S, p
timer = setInterval($(this).slide(parseInt('-' + options.distance)), options.delay);4 E) ?6 ?/ U( f9 f. S5 r
}else{* w) [: j( K& l" \
timer = setInterval($(this).slide(options.distance), options.delay);
( K- P# d% [; u }
( ` D5 v) ?3 y J4 t2 A});; g% }/ R# X/ P
};
: I, r7 _4 H- S9 I* ` $.fn.slide = function(distance){
" W1 f- ^3 M3 W# g1 \$ p5 @* { j var element = this;* j" j7 n; J$ L( J; G/ Z( R
return function(){# t, M# y+ J0 ]
var height = element.height() + distance;
! k/ Q) Y* I9 G0 w$ s if(typeof element.data('initAction') != 'undefined' && element.data('initAction')){% ~9 @% e; r8 D: L2 R: l. r2 J' g
height = 1;
5 v$ E: }& z/ I) c4 P element.height(height);) |7 ]. s7 x' s5 E
element.show();
, V' C- a$ _. z+ jelement.data('initAction', false);0 E- ~1 p( Q) G# D, j+ S
}
- U# _: T% D& _8 L H/ y; [ if(height < 0){
3 q1 k0 ]+ H/ u" U7 q2 J element.height(0);
: \1 K( z. _, C( o. c8 Q2 Q* B element.hide();2 {3 ]: D7 T5 `5 j0 M& D: Y
if(typeof element.data('initAction') != 'undefined' && !element.data('initAction')){5 W( @! y/ {9 G d5 y# t0 F
element.data('initAction', true);! b+ Q; x) r/ T4 u/ S6 C" w0 i, Y V
}
3 C) e/ ?, A8 A1 g ]1 k& V0 c. N' }clearInterval(timer);
" ]/ b" h; _0 ^ }else if(height > element.data('initHeight')){
" p) Y \9 c' U8 t1 f' x1 K element.height(element.data('initHeight'));8 o0 ?6 j4 p) Q7 P# u$ \4 H+ j% h3 {
clearInterval(timer);7 N: a: j# X3 l) K. l% v
}else{- J$ l8 y. H4 ?1 v& w
element.height(height);
# ~9 ~$ b( L' o6 m# y, i }
9 o' z+ t+ R1 `' }};
" ?7 p% ?8 D( {9 z) a8 b" E4 K }+ T7 W' A2 @; @" \ L# \' ?; R; j' w
})(jQuery)" h3 C# G1 d% O! w* R& K! T) C
, v" `( B" f+ `
, k6 l( P1 D) m) R( b1 l4 a3 H+ u4 T7 @- [) p
, C' X4 o) q2 S$ d3 Y! D1 W感谢溯游分享!!!
# G5 x1 f& r& N! F, _; I
* E) T7 ~6 l1 ]9 ^' w1 L+ X, c' z$ |
7 V( [- P- `1 R9 ?: W7 M B% C: b; y8 f
; a3 ~2 d c( O6 X+ z- u
|
|