2013-02-08 68 views
0

我已經使用循環插件和其他各種,但我不認爲他們會在這個例子中工作。我有最新的新聞欄目,是1行。例如:jQuery - 週期略有差異

最新消息 - 這是顯示

我通過各種新聞更新需要週期的信息。稍微不同的是我想更新slideRight(隱藏),然後下一個更新slideLeft(顯示)。這樣,寬度不斷變化,最新的新聞標題應該隨着更新的收縮和展開而左右移動(因爲它是內聯的,因此文本的寬度取決於文本)。因此,定位絕對寬度和固定寬度的解決方案無濟於事

我猜它的合理簡單,但林不知道如何。我可以從CSS開始,只定義要顯示的第一個p。然後在jQuery slideright current中,然後next()slideleft?

http://pastebin.com/2qCQeBMF http://pastebin.com/ERU9K8hC

回答

1

您可以在最後

/** 
* Method to animate the news feed 
*/ 
function scrollNews() { 
    // If latest news is not being hovered upon 
    if (!$('.latestnews').hasClass('hover')) { 
     // Get the currently visible update 
     var currentUpdate = $('.theupdates').find('p').filter(':visible').first(); 
     // Get the next update 
     var nextUpdate = currentUpdate.next(); 
     // If there are no next updates 
     if (nextUpdate.length === 0) { 
      // Get the first update and set it as the next update 
      nextUpdate = $('.theupdates').find('p').filter(':first-of-type'); 
     } 
     // Animate the current update out 
     currentUpdate.hide('slow', function() { 
      // Animate the next update in 
      nextUpdate.show('slow', function() { 
       // Delay a little bit and then recursively call this method 
       window.setTimeout(scrollNews, 2000); 
      }); 
     }); 
    } else { 
     // Delay a little bit and then recursively call this method 
     window.setTimeout(scrollNews, 2000); 
    } 
} 

// Handle hover over news 
$('.latestnews').on({ 
    'mouseover': function (e) { 
     $(this).addClass('hover'); 
    }, 
    'mouseout': function (e) { 
     $(this).removeClass('hover'); 
    } 
}); 

// Start animation 
scrollNews(); 

jsfiddle

+0

啊,這幾乎是完美的做了一系列的動畫,然後循環回來。我改變了動畫以顯示和隱藏(更多我想要的東西,但寧可左右滑動)。此外,我切換CSS,所以P和Strong顯示:block,因爲當jQuery顯示它改變爲阻止將其推到下面。唯一的問題是一次運行後循環停止,如何連續重複? – Michael 2013-02-08 19:38:03

+0

@Michael你看過最後一個更新的[jsfiddle](http://jsfiddle.net/vAutP/3/)例子嗎?它應該不斷循環。 – 2013-02-08 19:40:45

+0

這是我正在瞄準的效果的小提琴。略有不同是隱藏/表演。如果我更改爲jQuery UI,並且使用幻燈片方向會導致問題,並且出於某種原因文本會跳到下面。 [小提琴](http://jsfiddle.net/vAutP/9/) – Michael 2013-02-08 19:49:51