您可以在最後
/**
* 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
啊,這幾乎是完美的做了一系列的動畫,然後循環回來。我改變了動畫以顯示和隱藏(更多我想要的東西,但寧可左右滑動)。此外,我切換CSS,所以P和Strong顯示:block,因爲當jQuery顯示它改變爲阻止將其推到下面。唯一的問題是一次運行後循環停止,如何連續重複? – Michael 2013-02-08 19:38:03
@Michael你看過最後一個更新的[jsfiddle](http://jsfiddle.net/vAutP/3/)例子嗎?它應該不斷循環。 – 2013-02-08 19:40:45
這是我正在瞄準的效果的小提琴。略有不同是隱藏/表演。如果我更改爲jQuery UI,並且使用幻燈片方向會導致問題,並且出於某種原因文本會跳到下面。 [小提琴](http://jsfiddle.net/vAutP/9/) – Michael 2013-02-08 19:49:51