考慮以下標記:
<div id="marquee">My Text</div>
對於重複,我會做這樣的事情:
$("#marquee").wrapInner("span"); // wrap "My Text" with a new span
$("#marquee").append($("#marquee span").clone().hide()); // now there are two spans with "My Text"
移動和交換的跨度是挺容易。這是一個功能完整的例子:
$(function() {
var marquee = $("#marquee");
marquee.css({"overflow": "hidden", "width": "100%"});
// wrap "My Text" with a span (old versions of IE don't like divs inline-block)
marquee.wrapInner("<span>");
marquee.find("span").css({ "width": "50%", "display": "inline-block", "text-align":"center" });
marquee.append(marquee.find("span").clone()); // now there are two spans with "My Text"
// create an inner div twice as wide as the view port for animating the scroll
marquee.wrapInner("<div>");
marquee.find("div").css("width", "200%");
// create a function which animates the div
// $.animate takes a callback for when the animation completes
var reset = function() {
$(this).css("margin-left", "0%");
$(this).animate({ "margin-left": "-100%" }, 3000, 'linear', reset);
};
// kick it off
reset.call(marquee.find("div"));
});
See it in action。
免責聲明:
我不推薦任何專業的網站。不過,如果你想重現20世紀90年代的復古外觀,它可能會很有用。
讓我們派對就像是1995年! – Kevin 2010-01-26 23:40:36
你的傾向是完全正確的。 – 2010-01-27 02:51:52
我剛剛爲此創建了一個插件。希望這有助於:) https://github.com/aamirafridi/jQuery-Marquee – 2013-01-11 14:56:39