我目前有一个网站更改页面标题以反映当前正在播放的任何歌曲。我想要做的是让页面的标题不断滚动,这样用户就可以看到播放歌曲的全名,即使他们打开了很多标签。
我尝试了一些不同的滚动插件,但我发现效果最好的是这里的插件: http://www.seangw.com/wordpress/index.php/2009/01/basic-ajax-tutorial-smooth-scrolling-text-marquee-with-a-jquery-plugin/
我可以让插件在常规body元素上运行正常,但是当我将它放在页面标题上时它不起作用。我试过在标签中包装标签,但它不起作用。此外,我的页面标题会动态更改,因此滚动文本也需要更改。
以下是我正在更改标题的javascript函数:
function playNext(newState)
{
//alert("new state: " + newState);
//unstarted (-1), ended (0), playing (1), paused (2), buffering (3), video cued (5)
if(newState == 0) //song is done
{
//**************minimize myself*******************
var i = ' . $this->i .';
var dataString = getDataString(i);
minimizeSong(dataString, i);
//**************maximize next song****************
dataString = getDataString(i+1); //i + 1 is next song
maximizeSong(dataString, i+1);
//I will automatically start playing on load
}
else if(newState == 1) // if its playing, change the title
{
$("title").text("' . $this->title . ' by ' . $this->artist . ' - T3k.no");
}
else if(newState == 2) //song is paused, go back to original title
{
$("title").text("Paused - T3k.no");
}
else if(newState == 3) //song is buffering, change title
{
$("title").text("Loading '.$this->artist .' - T3k.no");
}
}
有人可以帮忙吗?我怎样才能实现这个目标?
这不起作用:
<html><head>
<marquee behavior="scroll" direction="left" scrollamount="2"
height="75" width="150">
<title>WANT THIS TO SCROLL</title>
</marquee>
</head></html>
但是这样的事情很好:
<body>
<marquee behavior="scroll" direction="left" scrollamount="2"
height="75" width="150">
<p>This is a test of a Smooth Marquee using jquery.</p>
</marquee>
</body>
答案 0 :(得分:2)
这是你的jQuery ready函数:
(function titleMarquee() {
document.title = document.title.substring(1)+document.title.substring(0,1);
setTimeout(titleMarquee, 200);
})();
marquee插件无法正常工作,因为 head 标记无法呈现。它的主要用途是设置页面及其资源。 选取框标记用于呈现的页面元素。 head 和 title 标记不在“正常流程”中。