2

これは、私がやろうとしていることのスニップセットです

$.pjax = function( options ) {
  var $container = $(options.container),
      success = options.success || $.noop

  // We don't want to let anyone override our success handler.
  delete options.success

  // We can't persist $objects using the history API so we must use
  // a String selector. Bail if we got anything else.
  if ( typeof options.container !== 'string' )
    throw "pjax container must be a string selector!"

  var defaults = {
    timeout: 650,
    push: true,
    replace: false,
    // We want the browser to maintain two separate internal caches: one for
    // pjax'd partial page loads and one for normal page loads. Without
    // adding this secret parameter, some browsers will often confuse the two.
    data: { _pjax: true },
    type: 'GET',
    dataType: 'html',
    beforeSend: function(xhr){
      $container.trigger('start.pjax')
      xhr.setRequestHeader('X-PJAX', 'true')
    },
    error: function(){
      window.location = options.url
    },
    complete: function(){


$container.trigger('end.pjax')
},
success: function(data){
  // If we got no data or an entire web page, go directly
  // to the page and let normal error handling happen.
  if ( !$.trim(data) || /<html/i.test(data) )
    return window.location = options.url

  // Make it happen.
  // i think im not getting it right.
  $(window).load(
      function() {
          $container.html(data)
      }
  );

jQueryにすべての画像がロードされるのを待ってから何かを実行するように頼む公式の方法のようですが、それはjquery ajaxリクエストの後でした。

下部にあるように、html(data) からのすべての画像を提供する準備ができた後に html(data)// Make it happenを返そうとしていますが、どうにかしてそれを行うことはできますか?

ありがとう!

アダム・ラマダン

4

1 に答える 1

0

ブラウザーが画像の読み込みを開始する前に、読み込まれた HTML を DOM に挿入する必要があると思います。display:none非表示の ( ) divに挿入し、.load()その非表示の div にコールバックを設定できるはずです。

このプラグイン.load()は、画像の読み込み時にイベントがより一貫してトリガーされるようにイベントを改善します。

于 2011-06-18T03:39:58.393 に答える