Javascript 如何使用css控制此js脚本中的嵌入文本
我没有控制原始脚本的权限,所以我正在尝试使用css为这个滚动文本脚本创建文本样式,我一点运气都没有Javascript 如何使用css控制此js脚本中的嵌入文本,javascript,jquery,css,Javascript,Jquery,Css,我没有控制原始脚本的权限,所以我正在尝试使用css为这个滚动文本脚本创建文本样式,我一点运气都没有 <script type="text/javascript"> scrollingTextSpeed = 75; scrollingTextDirection = "Ticker"; scrollingTextx = 500; scrollingTexty = 40 * 2; scrollingTextxOffset = 6; scrollingTextyOffset = 3; v
<script type="text/javascript">
scrollingTextSpeed = 75;
scrollingTextDirection = "Ticker";
scrollingTextx = 500;
scrollingTexty = 40 * 2;
scrollingTextxOffset = 6;
scrollingTextyOffset = 3;
var scrollingTextArray = new Array();
scrollingTextArray[0] = "Mock drafts available...";
scrollingTextArray[1] = "Link found in My League menu above...";
scrollingTextArray[2] = "Click on Find Mock Draft...";
scrollingTextArray[3] = "Winners prepare!";
;
scrollingTextIndex = 0;
function animateScrollingText () {
var ctx = document.getElementById('scrollingText').getContext('2d');
var displayText = scrollingTextArray[scrollingTextIndex];
ctx.fillStyle = "#000000";
// ctx.fillStyle = document.body.style.color;
ctx.font = "18" + "pt Verdana";
ctx.clearRect(0,0,500,40);
var dim = ctx.measureText(displayText);
if (scrollingTextDirection == "Ticker") {
scrollingTexty = 40/2;
scrollingTextx -= scrollingTextxOffset;
if (scrollingTextx < (dim.width * -1)) {
scrollingTextx = 500;
scrollingTextIndex++;
if (scrollingTextIndex >= scrollingTextArray.length) {
scrollingTextIndex = 0;
}
}
} else {
scrollingTextx = Math.round((500 - dim.width) / 2);
scrollingTexty -= scrollingTextyOffset;
if (scrollingTexty < 0) {
scrollingTexty = 100;
scrollingTextIndex++;
if (scrollingTextIndex >= scrollingTextArray.length) {
scrollingTextIndex = 0;
}
}
}
if (document.getElementById("scrollingTextLocation")) {
document.getElementById("scrollingTextLocation").innerHTML = "scrollingTextx = " + scrollingTextx + ", scrollingTexty = " + scrollingTexty;
}
ctx.fillText(displayText,scrollingTextx,scrollingTexty);
}
</script>
scrollingTextSpeed=75;
scrollingTextDirection=“Ticker”;
scrollingTextx=500;
scrollingTexty=40*2;
scrollingTextxOffset=6;
scrollingTextyOffset=3;
var scrollingTextArray=新数组();
scrollingTextArray[0]=“模拟草稿可用…”;
scrollingTextArray[1]=“在上面的我的联盟菜单中找到链接…”;
scrollingTextArray[2]=“单击查找模拟草稿…”;
scrollingTextArray[3]=“赢家准备!”;
;
scrollingdex=0;
函数animateSrollingText(){
var ctx=document.getElementById('scrollingText').getContext('2d');
var displayText=scrollingTextArray[ScrollingTesteIndex];
ctx.fillStyle=“#000000”;
//ctx.fillStyle=document.body.style.color;
ctx.font=“18”+“pt Verdana”;
ctx.clearRect(0,0500,40);
var dim=ctx.measureText(显示文本);
如果(scrollingTextDirection==“Ticker”){
scrollingTexty=40/2;
scrollingTextx-=scrollingTextxOffset;
如果(滚动文本X<(尺寸宽度*-1)){
scrollingTextx=500;
滚动dex++;
if(ScrollingTesteIndex>=scrollingTextArray.length){
scrollingdex=0;
}
}
}否则{
scrollingTextx=数学圆((500-尺寸宽度)/2);
scrollingTexty-=scrollingTextyOffset;
如果(滚动文本<0){
scrollingTexty=100;
滚动dex++;
if(ScrollingTesteIndex>=scrollingTextArray.length){
scrollingdex=0;
}
}
}
if(document.getElementById(“scrollingTextLocation”)){
document.getElementById(“scrollingTextLocation”).innerHTML=“scrollingTextx=“+scrollingTextx+”,scrollingTexty=“+scrollingTexty;
}
fillText(displayText、scrollingTextx、scrollingTexty);
}
这是html,我希望能够控制字体的颜色和大小
我试过#滚动文本{颜色:红色!重要}和画布#滚动文本{颜色:红色!重要}
<div align="center">
<canvas id="scrollingText" width="500" height="40">
HTML5 Scrolling text goes here!
</canvas>
</div>
HTML5滚动文本在这里!
您的滚动文本不是由DOM元素组成的。使用CSS根本无法控制它
您拥有的唯一控件是使用画布的上下文函数和属性,如已使用的函数和属性:
ctx.fillStyle = "#000000";
ctx.font = "18" + "pt Verdana";
要将颜色设置为红色,请使用
ctx.fillStyle = "red";
使用#scrollingText或canvas#scrollingText甚至添加都不起作用!重要提示:如果可能的话,使用ctx.fillStyle=“#000000”)添加一个覆盖脚本并控制颜色;但是我不写js,也不会有cluecan,我可以加载一个单独的脚本函数来设置颜色和字体大小吗?如果是的话,你能告诉我会是什么吗,谢谢,你可以加载一个几乎相同的脚本,只需改变我显示的颜色。加载第一个后再加载。我需要全部使用它,还是只使用列出的颜色填充样式的简化版本?您需要所有东西。你已经用JavaScript编程了吗?还是这是第一次?非常感谢你对我的帮助