0

私はこれを尋ねる方法が本当にわからないので、ここにスクリプトを書きました:http: //jsbin.com/acaxi/edit
それはかなり簡単です、私はスライディングパネルを作成しようとしています。

私はそれをうまく行うスクリプトがたくさんあることを知っています、正直に言うと多すぎます。

私のスクリプトの代わりにあなたがお勧めできるプラグインがあると誰かが思ったら、共有してください!

4

1 に答える 1

1

あなたの質問が何であるかはまだわかりませんが、任意の数のフィードパネルで機能するようにコードを少し作り直しました(更新されたデモ)。

$(document).ready(function(){

  var feeds = $('#feeds div'),
      numFeeds = feeds.length;

  feeds
    .click(function(){
      $(this)
        .animate({"margin-left": "-200px", opacity: 0}, "fast")
        .animate({"margin-left": "200px"}, "fast");
      // add 2 since the id isn't zero based
      var next = ( $(this).index() + 2 > numFeeds ) ? 1 : $(this).index() + 2;
      $('div#feed' + next).animate({"margin-left": 0, opacity: 1}, "fast")
    })
    .nextAll().css({ 'margin-left' : '200px', opacity : 0 });

});

フィードを動的に追加するには、追加された新しいフィードごとにクリック関数をアタッチするか、jQuery .live()イベントハンドラーを使用する必要があります。私は前の方法を選びました。更新されたデモとコードは次のとおりです。

$(document).ready(function(){

  var feeds = $('#feeds .feeds'),
      numFeeds = feeds.length;

  // initialize
  feeds
   .click(function(){ animateFeed(this, numFeeds); })
   .nextAll().css({ 'margin-left' : '200px', opacity : 0 });

  // add another feed
  $('.addFeed').click(function(){
   $('<div id="feed' + ( numFeeds++ +1 ) + '" class="feeds">' + numFeeds +'</div>')
    .click(function(){ animateFeed(this, numFeeds); })
    .css({ 'margin-left' : '200px', opacity : 0 })
    .appendTo(feeds.parent());
   $('#num').text(numFeeds);
  })

});

// animate feed panel
function animateFeed(el, num){
 var indx = $(el).index(),
     next = ( indx + 1 ) % num;
 $('.feeds').removeClass('active');
 $(el)
  .animate({ marginLeft : '-200px', opacity: 0}, 'fast')
  .animate({ marginLeft : '200px'}, 'fast' );
 $('.feeds:eq(' + next + ')').animate({ marginLeft : 0, opacity : 1}, 'fast', function(){ $(this).addClass('active') } );
}
于 2010-05-12T21:10:18.030 に答える