我正在尝试创建我认为世界上最糟糕的网站。 我想在带有标记的文本中添加一些JavaScript。我已经尝试了一些方法来自己修复它,但是我无法解决这个问题。我该如何运作?
(该脚本应该使文本变成彩虹色,顺便说一句) 脚本,包括我的文字:
var text= <marquee>"hello and welcoem to my website"</marquee> // YOUR TEXT
var speed=80 // SPEED OF FADE
// ********** LEAVE THE NEXT BIT ALONE!
var el = document.getElementsByTagName('marquee')[0];
if (document.all||document.getElementById){
document.write('<span id="highlight">' + text + '</span>')
var storetext=document.getElementById? document.getElementById("highlight") : document.all.highlight
}
else
document.write(text)
var hex=new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0")
var r=1
var g=1
var b=1
var seq=1
function changetext(){
rainbow="#"+hex[r]+hex[g]+hex[b]
storetext.style.color=rainbow
}
function change(){
if (seq==6){
b--
if (b==0)
seq=1
}
if (seq==5){
r++
if (r==12)
seq=6
}
if (seq==4){
g--
if (g==0)
seq=5
}
if (seq==3){
b++
if (b==12)
seq=4
}
if (seq==2){
r--
if (r==0)
seq=3
}
if (seq==1){
g++
if (g==12)
seq=2
}
changetext()
}
function starteffect(){
if (document.all||document.getElementById)
flash=setInterval("change()",speed)
}
starteffect()
</script>
</b>
答案 0 :(得分:0)
尝试一下...在https://codepen.io/cunlay/pen/jOOmaRv上工作
<b>
<script>
var text = "<marquee>hello and welcome to my website</marquee>"; // YOUR TEXT
var speed = 80; // SPEED OF FADE
var r = 1, g = 1, b = 1, seq = 1;
var hex = new Array("00","14","28","3C","50","64","78","8C","A0","B4","C8","DC","F0");
var storetext;
// ********** LEAVE THE NEXT BIT ALONE!
var el = document.getElementsByTagName('marquee')[0];
if (document.all || document.getElementById){
document.write('<span id="highlight">' + text + '</span>');
}else{
document.write(text);
}
function changetext(){
var rainbow = "#"+hex[r]+hex[g]+hex[b];
storetext = document.getElementById("highlight");
storetext.style.color = rainbow;
}
function change(){
if(seq==6){
b--;
if(b==0){
seq=1;
}
}else if (seq==5){
r++;
if (r==12){
seq=6;
}
}else if (seq==4){
g--;
if(g==0){
seq=5;
}
}else if (seq==3){
b++;
if (b==12){
seq=4;
}
}else if (seq==2){
r--;
if(r==0){
seq=3;
}
}else if (seq==1){
g++;
if(g==12){
seq=2;
}
}else {
return false;
}
changetext();
}
function starteffect(){
if (document.all || document.getElementById){
var flash = setInterval("change()",speed);
}
return false;
}
starteffect();
</script>
</b>