検索
ホームページウェブフロントエンドjsチュートリアルJquery1.9.1のソースコード解析シリーズ(15)アニメーション処理のその先_jquery

a. Tween.propHooks と互換性のあるアニメーション

Tween.propHooks は、特殊な状況下で CSS 特徴値を設定および取得するためのメソッドを提供します。構造は次のとおりです。

Tween.propHooks = {
  _default: {
    get: function(){...},
    set: function(){...}
  },
  scrollTop: {
    set: function(){...}
  }
  scrollLeft: {
    set: function(){...}
  }
} 

Tween.propHooks.scrollTop と Tween.propHooks.scrollLeft は、IE8 がオフラインで CSS 特徴値がノードに保存されているときの混乱が主な原因です

set: function( tween ) {
  if ( tween.elem.nodeType && tween.elem.parentNode ) {
    tween.elem[ tween.prop ] = tween.now;
  }
} 

Tween.propHooks._default の get メソッドは、css の tween.prop 特徴量をノードから直接取得しようとしますが、取得できない場合は、jQuery.css() メソッドを使用して取得します。このメソッドの処理では、「10px」などの単純な値は浮動小数点数として解析され、「回転(1rad)」などの複雑な値はそのまま返されます。次に、返された結果を処理します。空の文字列、null、未定義、および「auto」は 0 に変換され、その他の条件は変更されません。

get: function( tween ) {
  var result;
  if ( tween.elem[ tween.prop ] != null &&
    (!tween.elem.style || tween.elem.style[ tween.prop ] == null) ) {
    return tween.elem[ tween.prop ];
  }
  //传递一个空字符串作为第三个参数的.css会自动尝试parseFloat,
  //并返回到一个字符串,如果解析失败的话。
  //所以,简单的值,如“10px”会被被解析为浮点数。复杂的值,如“旋转(1rad)”返回原样。
  result = jQuery.css( tween.elem, tween.prop, "" );
  // 空字符串, null, undefined 和 "auto"都转化为0
  return !result || result === "auto" ? 0 : result;
} 

Tween.propHooks._default の set メソッドは、最初に jQuery.fx.step[tween.prop ] を使用して下位互換性を設定します。それ以外の場合は、最も極端な CSS 機能値を設定するために jQuery.style が使用されます。この場合、特徴値はノードに直接保存されます

set: function( tween ) {
  //使用step hook向下兼容 - 使用cssHook如果他存在 - 使用.style如果可用的话
  //使用直接的特征值如果可用可用的话
  if ( jQuery.fx.step[ tween.prop ] ) {
    jQuery.fx.step[ tween.prop ]( tween );
  } else if ( tween.elem.style && ( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null || jQuery.cssHooks[ tween.prop ] ) ) {
    jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
  } else {
    tween.elem[ tween.prop ] = tween.now;
  }
} 

b. アニメーション固有のオブジェクト jQuery.fx

jQuery.fx は、アニメーション アクションを実行するために使用されるいくつかの関数をカプセル化します。その構造は次のとおりです。

jQuery.fx = {
  tick = function () {...},//每个时间点都会执行的函数外壳,会取出jQuery.timers中的函数执行
  timer = function ( timer ) {...},//执行参数中的函数并启动计时
  interval = 13, //计时步长
  start = function () {...},//启动计时
  stop = function () {...},//停止计时
  speeds = {slow: 600,fast: 200,_default: 400},//动画速度(完整动画执行时间)
  step = {}//向下兼容<1.8扩展点
} 

詳細なソースコード分析は次のとおりです

jQuery.fx = Tween.prototype.init;
//每个时间点都会执行的函数外壳,会取出jQuery.timers中的函数执行
jQuery.fx.tick = function() {
  var timer,
  timers = jQuery.timers,
  i = 0;
  fxNow = jQuery.now();
  for ( ; i < timers.length; i++ ) {
    timer = timers[ i ];
    // Checks the timer has not already been removed
    if ( !timer() && timers[ i ] === timer ) {
      timers.splice( i--, 1 );
    }
  }
  if ( !timers.length ) {
    jQuery.fx.stop();
  }
  fxNow = undefined;
};
//执行参数中的函数并启动计时
jQuery.fx.timer = function( timer ) {
  if ( timer() && jQuery.timers.push( timer ) ) {
    jQuery.fx.start();
  }
};
//计时步长
jQuery.fx.interval = 13;
//启动计时
jQuery.fx.start = function() {
  if ( !timerId ) {
    timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
  }
};
//停止计时
jQuery.fx.stop = function() {
  clearInterval( timerId );
  timerId = null;
};
//动画速度(完整动画执行时间)
jQuery.fx.speeds = {
  slow: 600,
  fast: 200,
  // Default speed
  _default: 400
};
//向下兼容<1.8扩展点
jQuery.fx.step = {}; 
  这里其中执行动画的关键源码是
//动画入口函数function Animation( elem, properties, options ){
  ...
  jQuery.fx.timer(
    jQuery.extend( tick, {
      elem: elem,
      anim: animation,
      queue: animation.opts.queue
    })
  );
  ...
}
//执行参数中的函数并启动计时
jQuery.fx.timer = function( timer ) {
  if ( timer() && jQuery.timers.push( timer ) ) {
    jQuery.fx.start();
  }
};
//计时步长
jQuery.fx.interval = 13;
//启动计时
jQuery.fx.start = function() {
  if ( !timerId ) {
    timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
  }
}; 

変数 jQuery.timers = []; は、ティックごとに実行する必要がある関数のリストを保存するために使用されます。一般に、関数は 1 つだけあり、それはアニメーション関数で定義されているティック関数です。 jQuery.fx.interval を使用して、アニメーションの 2 フレームごとの時間間隔を設定できます。デフォルトは 13 ミリ秒です。

アニメーションの分析は以上です。以下はアニメーション関連の API のリストです

jQuery.fn.show([ period ] [, easing ] [, complete ] | options ) (一致する要素をすべて表示します。さらに、要素表示の遷移アニメーション効果も指定できます。要素自体が要素が非表示の場合は、要素を表示します。この関数の逆は、一致するすべての要素を非表示にするために使用される関数です。

jQuery.fn.hide([ period ] [, easing ] [, complete ] | options) (一致する要素をすべて非表示にします。さらに、要素の非表示にトランジション アニメーション効果を指定することもできます。要素自体が非表示の場合)
が表示されている場合、要素は変更されません。

jQuery.fn.toggle([ period ] [, easing ] [, complete ] | options) (一致するすべての要素を切り替えます。さらに、要素切り替えの遷移アニメーション効果を指定することもできます。いわゆる「トグル」 "、つまり、要素が現在表示されている場合は非表示にし、要素が現在非表示の場合は表示 (可視) にします)

今回紹介するtoggle()関数は要素の表示・非表示を切り替えるために使用します。 jQuery には、同じ名前のイベント関数 toggle() もあります。これは、クリック イベントをバインドし、トリガーされたときにさまざまなイベント処理関数を順番に実行するように切り替えるために使用されます。

jQuery.fn.slideDown([ due ] [, easing ] [, complete ] | options) (下方向にスライドするアニメーション効果を持つすべての一致する要素を表示します。下方向にスライドするアニメーション効果、つまり要素の高さは表示領域は 0 から元の高さまで徐々に増加します (要素自体が表示されている場合は変更されません)。要素が非表示の場合は表示されます。

この関数の反対は、slideUp() 関数です。この関数は、上向きにスライドするトランジション アニメーション効果で一致する要素をすべて非表示にするために使用されます)


jQuery.fn.slideUp([ due ] [, easing ] [, complete ] | options) (上向きにスライドする遷移アニメーション効果を使用して、一致する要素をすべて非表示にします。上向きにスライドするアニメーション効果は、要素の表示領域です。高さは元の高さから 0 まで徐々に減少します (要素自体が非表示の場合、要素は表示されますが、要素は非表示になります)。


jQuery.fn.slideToggle([ period ] [, easing ] [, complete ] | options) (スライド遷移アニメーション効果を使用して、一致するすべての要素を切り替えます。いわゆる「切り替え」とは、要素が現在 If要素が表示されている場合は非表示にします (上にスライド)、要素が現在非表示になっている場合は表示します (下にスライド))。

jQuery.fn.fadeIn([ due ] [, easing ] [, complete ] | options) (フェードイン遷移アニメーション効果を使用して、一致するすべての要素を表示します。フェードイン アニメーション効果は、要素の不透明度です。スケールは 0% から 100% まで徐々に増加します。要素自体が表示されている場合は変更されません。要素が非表示の場合は、この関数が使用されます。すべてを非表示にします。フェードアウト トランジション アニメーション効果を使用して要素を一致させます)

jQuery.fn.fadeOut([ period ] [, easing ] [, complete ] | options) (フェードアウト遷移アニメーション効果を使用して、一致する要素をすべて非表示にします。いわゆる「フェードアウト」アニメーション効果は、要素の不透明度スケールは 100% から 0% まで徐々に減少します。要素自体が非表示の場合、要素は変更されません。要素が表示されている場合は非表示になります。

jQuery.fn.fadeToggle([ period ] [, easing ] [, complete ] | options) (フェードイン/フェードアウトのトランジション アニメーション効果を使用して、一致するすべての要素を切り替えます。いわゆる「スイッチ」とは、次の場合を意味します。要素が現在表示されている場合は非表示 (フェードアウト)、要素が現在非表示の場合は表示します (フェードイン))。

jQuery.fn.animate(cssProperties [, period ] [, easing ] [, complete ] | cssProperties, options) (CSS プロパティに基づいてカスタム アニメーションを実行します。一致する要素の CSS スタイルを設定できます。animate( ) 関数現在のスタイルから指定された CSS スタイルへの遷移アニメーションを実行します。 たとえば、div 要素の現在の高さが 100 ピクセルの場合、CSS の高さプロパティを 200 ピクセルに設定すると、animate() は div 要素の遷移アニメーションを実行します。高さは 100px から 200px まで徐々に増加します)


jQuery.fn.lay(duration [, queueName]) (キュー内の次の項目の実行を遅らせます。lay() は、キュー内で実行を待っている次のアニメーションを、実行する前に指定した時間遅らせることができます。これは通常、2 つの jQuery エフェクト関数間のキューで使用され、それにより、前のアニメーション効果が実行された後、次のアニメーション効果の実行時間を遅らせます。次の項目がエフェクト アニメーションでない場合、そのアイテムはエフェクト キューに追加されません。したがって、この関数は遅延呼び出しを行いません)


jQuery.fn.stop([ queueName ] [, clearQueue [, jumpToEnd ] ]) (Stop the currently running animation on the matching element. By default, the stop() function will only stop the currently running animation. If You use the animate() function to set three animations A, B, and C for the current element. If the currently executing animation is A, it will only stop the execution of animation A and will not prevent the execution of animations B and C. Of course. , you can also stop all animations by specifying optional option parameters. Stopping the animation does not restore the state before the animation is executed, but stops it directly. The current animation execution state will stay in that state. For example: Execute a transition animation from 100px to 200px for an element's height. If the animation is stopped when the height is 150px, the current height will still remain at 150px. If the animation sets a callback function after execution, the callback function will not be executed. . )

jQuery.fn.finish([ queueName ]) (immediately completes all animations in the queue. finish() stops the currently running animation, deletes all animations in the queue, and completes all animations of matching elements)

jQuery.fn. fadeTo([speed,]opacity[,callback]) (gradually changes the opacity of the selected element to the specified value)

jQuery.fx.off (This property is used to set or return whether all animations are globally disabled. If this property is not set, a Boolean value indicating whether animation effects are globally disabled is returned. If this property is Set to true to disable all animations globally. Any animation queues that are not yet executed will be completed immediately without animation effects. false, will enable the animation effect globally
.

You can disable animation effects when you encounter the following situations: you are using jQuery on a computer with low configuration; some users may encounter accessibility issues due to animation effects. )

jQuery.fx.interval (This property is used to set or return the frame rate of the animation (millisecond value). The jQuery.fx.interval property is used to set how many milliseconds the jQuery animation draws a frame of image (triggering a style change, The browser may redraw the current page). The smaller the value, the more times the animation is triggered and the animation effect is more obvious and smoother. Of course, the animation queue being executed when changing the value of this property will consume more performance. will not be affected. Any animation queue that has not yet been executed will draw animation effects at the changed frame rate)

The above content is excluding animation processing of Jquery 1.9.1 source code analysis series (fifteenth) introduced by the editor of Script House. Animation processing of jQuery 1.9.1 source code analysis series (fifteen), click to learn more.

声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
JavaScriptとWeb:コア機能とユースケースJavaScriptとWeb:コア機能とユースケースApr 18, 2025 am 12:19 AM

Web開発におけるJavaScriptの主な用途には、クライアントの相互作用、フォーム検証、非同期通信が含まれます。 1)DOM操作による動的なコンテンツの更新とユーザーインタラクション。 2)ユーザーエクスペリエンスを改善するためにデータを提出する前に、クライアントの検証が実行されます。 3)サーバーとのリフレッシュレス通信は、AJAXテクノロジーを通じて達成されます。

JavaScriptエンジンの理解:実装の詳細JavaScriptエンジンの理解:実装の詳細Apr 17, 2025 am 12:05 AM

JavaScriptエンジンが内部的にどのように機能するかを理解することは、開発者にとってより効率的なコードの作成とパフォーマンスのボトルネックと最適化戦略の理解に役立つためです。 1)エンジンのワークフローには、3つの段階が含まれます。解析、コンパイル、実行。 2)実行プロセス中、エンジンはインラインキャッシュや非表示クラスなどの動的最適化を実行します。 3)ベストプラクティスには、グローバル変数の避け、ループの最適化、constとletsの使用、閉鎖の過度の使用の回避が含まれます。

Python vs. JavaScript:学習曲線と使いやすさPython vs. JavaScript:学習曲線と使いやすさApr 16, 2025 am 12:12 AM

Pythonは、スムーズな学習曲線と簡潔な構文を備えた初心者により適しています。 JavaScriptは、急な学習曲線と柔軟な構文を備えたフロントエンド開発に適しています。 1。Python構文は直感的で、データサイエンスやバックエンド開発に適しています。 2。JavaScriptは柔軟で、フロントエンドおよびサーバー側のプログラミングで広く使用されています。

Python vs. JavaScript:コミュニティ、ライブラリ、リソースPython vs. JavaScript:コミュニティ、ライブラリ、リソースApr 15, 2025 am 12:16 AM

PythonとJavaScriptには、コミュニティ、ライブラリ、リソースの観点から、独自の利点と短所があります。 1)Pythonコミュニティはフレンドリーで初心者に適していますが、フロントエンドの開発リソースはJavaScriptほど豊富ではありません。 2)Pythonはデータサイエンスおよび機械学習ライブラリで強力ですが、JavaScriptはフロントエンド開発ライブラリとフレームワークで優れています。 3)どちらも豊富な学習リソースを持っていますが、Pythonは公式文書から始めるのに適していますが、JavaScriptはMDNWebDocsにより優れています。選択は、プロジェクトのニーズと個人的な関心に基づいている必要があります。

C/CからJavaScriptへ:すべてがどのように機能するかC/CからJavaScriptへ:すべてがどのように機能するかApr 14, 2025 am 12:05 AM

C/CからJavaScriptへのシフトには、動的なタイピング、ゴミ収集、非同期プログラミングへの適応が必要です。 1)C/Cは、手動メモリ管理を必要とする静的に型付けられた言語であり、JavaScriptは動的に型付けされ、ごみ収集が自動的に処理されます。 2)C/Cはマシンコードにコンパイルする必要がありますが、JavaScriptは解釈言語です。 3)JavaScriptは、閉鎖、プロトタイプチェーン、約束などの概念を導入します。これにより、柔軟性と非同期プログラミング機能が向上します。

JavaScriptエンジン:実装の比較JavaScriptエンジン:実装の比較Apr 13, 2025 am 12:05 AM

さまざまなJavaScriptエンジンは、各エンジンの実装原則と最適化戦略が異なるため、JavaScriptコードを解析および実行するときに異なる効果をもたらします。 1。語彙分析:ソースコードを語彙ユニットに変換します。 2。文法分析:抽象的な構文ツリーを生成します。 3。最適化とコンパイル:JITコンパイラを介してマシンコードを生成します。 4。実行:マシンコードを実行します。 V8エンジンはインスタントコンピレーションと非表示クラスを通じて最適化され、Spidermonkeyはタイプ推論システムを使用して、同じコードで異なるパフォーマンスパフォーマンスをもたらします。

ブラウザを超えて:現実世界のJavaScriptブラウザを超えて:現実世界のJavaScriptApr 12, 2025 am 12:06 AM

現実世界におけるJavaScriptのアプリケーションには、サーバー側のプログラミング、モバイルアプリケーション開発、モノのインターネット制御が含まれます。 2。モバイルアプリケーションの開発は、ReactNativeを通じて実行され、クロスプラットフォームの展開をサポートします。 3.ハードウェアの相互作用に適したJohnny-Fiveライブラリを介したIoTデバイス制御に使用されます。

next.jsを使用してマルチテナントSaaSアプリケーションを構築する(バックエンド統合)next.jsを使用してマルチテナントSaaSアプリケーションを構築する(バックエンド統合)Apr 11, 2025 am 08:23 AM

私はあなたの日常的な技術ツールを使用して機能的なマルチテナントSaaSアプリケーション(EDTECHアプリ)を作成しましたが、あなたは同じことをすることができます。 まず、マルチテナントSaaSアプリケーションとは何ですか? マルチテナントSaaSアプリケーションを使用すると、Singの複数の顧客にサービスを提供できます

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

ドリームウィーバー CS6

ドリームウィーバー CS6

ビジュアル Web 開発ツール

AtomエディタMac版ダウンロード

AtomエディタMac版ダウンロード

最も人気のあるオープンソースエディター

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境

SublimeText3 Mac版

SublimeText3 Mac版

神レベルのコード編集ソフト(SublimeText3)

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、