簡體   English   中英

jQuery BBQ:添加諸如衰落,幻燈片等過渡效果

[英]jQuery BBQ: Adding transitions like fading, slide, etc

第一次在這里問一個問題,但是我狂熱地使用stackoverflow。

我創建了一個使用jQuery BBQ來以AJAX方式加載頁面的網站,但仍然能夠使用“后退”按鈕等來跟蹤歷史記錄...

開箱即用BBQ的只是使用.hide().show()函數中要加載的內容。 我想知道修改此屬性以實現無縫過渡(例如衰落)的最佳方法。

這是代碼:

$(function(){

  // Keep a mapping of url-to-container for caching purposes.
  var cache = {
    // If url is '' (no fragment), display this div's content.
    '': $('#home')
  };

  // Bind an event to window.onhashchange that, when the history state changes,
  // gets the url from the hash and displays either our cached content or fetches
  // new content to be displayed.
  $(window).bind( 'hashchange', function(e) {

    // Get the hash (fragment) as a string, with any leading # removed. Note that
    // in jQuery 1.4, you should use e.fragment instead of $.param.fragment().
    var url = $.param.fragment();

    // Remove .current class from any previously "current" link(s).
    $( 'a.current' ).removeClass( 'current' );

    // Hide any visible ajax content.
    $( '#main' ).children( ':visible' ).hide(1000);


    // Add .current class to "current" nav link(s), only if url isn't empty.
    url && $( 'a[href="#' + url + '"]' ).addClass( 'current' );

    if ( cache[ url ] ) {
      // Since the element is already in the cache, it doesn't need to be
      // created, so instead of creating it again, let's just show it!
      cache[ url ].show(1000);

    } else {
      // Show "loading" content while AJAX content loads.
      $( '.bbq-loading' ).show();

      // Create container for this url's content and store a reference to it in
      // the cache.
     //$('.page:visible').fadeout(1000);
       url  = $( '<div class="page"/>' )

        // Append the content container to the parent container.
        .appendTo( '#main' )

        // Load external content via AJAX. Note that in order to keep this
        // example streamlined, only the content in .infobox is shown. You'll
        // want to change this based on your needs.
        .load( url, function(){
          // Content loaded, hide "loading" content.
          $( '.bbq-loading' ).hide();

        });
    }
  })

  // Since the event is only triggered when the hash changes, we need to trigger
  // the event now, to handle the hash the page may have loaded with.
  $(window).trigger( 'hashchange' );

});

如您所見,我有一個.show(1000) .hide(1000).show(1000) ,但是它似乎會刷新頁面上的所有內容,即使不是<div id="main">內的元素也是如此。

任何幫助將非常感激。 抱歉,由於我和客戶之間是機密信息,因此無法包含該示例。

您應該使用組合jquery addClass + css,但您也可以通過淡入淡出或設置動畫來在純jQuery中執行此操作,如下所示:

//fadeOut the element
.fadeOut(1000);
.animate({opacity: 0}, 1000);

//fadeIn the element
.fadeIn(1000);
.animate({opacity: 1}, 1000);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM