有没有可能在jQuery中创建一个100%无缝的字幕(或者仅仅是javascript,但jQuery更好)?
我做了一个简单的选框,它向左移动,直到它离开屏幕,然后简单地跳到右边(当看不到的时候),然后重新开始。然而,我希望不用再等了。
我能想到的唯一方法是复制文本并将其放在第一个文本之后,然后再次交换它们。然而,我不知道如何在jQuery中实现这一点,我一直在研究jQuery的.clone(),但无法让它正常工作,一切都会跳转。
有什么想法吗?
耽误您时间,实在对不起,
发布于 2010-01-27 06:18:49
给定以下标记:
<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。
免责声明:
我不推荐在任何专业网站上这样做。但是,如果你想重现90年代的复古外观,它可能会很有用。
https://stackoverflow.com/questions/2143056
复制相似问题