0
一直致力於在我的網站中實現滾動新聞自動收報器。用JS控制滾動功能。我使用的代碼如下,任何人都可以告訴我如何設置和滾動股票滾動的速度?Javascript - 設置和控制滾動速度
$(function() {
//cache the ticker to improve the performance of the page.
var ticker = $("#ticker");
//wrap dt:dd pairs in divs to allow us to smooth our the animations
ticker.children().filter("dt").each(function() {
var dt = $(this),
container = $("<div>");
dt.next().appendTo(container);
dt.prependTo(container);
container.appendTo(ticker);
});
//hide the scrollbar
ticker.css("overflow", "hidden");
//animator function
function animator(currentItem) {
//work out new anim duration
var distance = currentItem.height();
duration = (distance + parseInt(currentItem.css("marginTop")))/0.025;
//animate the first child of the ticker
currentItem.animate({ marginTop: -distance }, duration, "linear", function() {
//move current item to the bottom
currentItem.appendTo(currentItem.parent()).css("marginTop", 0);
//recurse
animator(currentItem.parent().children(":first"));
});
};
// start the news section scrolling
animator(ticker.children(":first"));
// users mouse enters the scrolling view
ticker.mouseenter(function() {
// Im stopping the animation when the mouse enters
ticker.children().stop();
});
// the mouse now leaves the view
ticker.mouseleave(function() {
// begin the animating again of the scroller
animator(ticker.children(":first"));
});
});
感謝
感謝您的回覆,我認爲從'教程'網站使用代碼學習並不是壞事,不是每個人都可以成爲專家程序員。是的,我曾嘗試過使用相同部分的代碼嘗試失敗,但我會再試一次。謝謝 –