我沒有權限控制原始腳本,因此我試圖使用css爲此滾動文本腳本創建文本樣式,而且我根本沒有任何運氣。如何使用css控制此js腳本中的嵌入文本
<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>
這裏是HTML,我希望能夠CONTRAL字體顏色和大小 我曾嘗試#scrollingText {顏色:紅色重要}和帆布#scrollingText {顏色:紅色重要}
<div align="center">
<canvas id="scrollingText" width="500" height="40">
HTML5 Scrolling text goes here!
</canvas>
</div>
它的使用不工作#scrollingText或canvas#scrollingText,甚至添加!重要的 – user2692296
想知道是否有可能爲此腳本添加騎行並用ctx.fillStyle =「#000000」控制顏色。但我不寫js,不會有線索 – user2692296