我有一个函数将文本附加到带有某种颜色效果的div
。 我想让文字出现在单词之后。 (但是我只需要在第二个函数的参数“str”的文本上使用这个效果,那么“who”必须显得正常。 我找到了一个我需要的效果代码,但是我不知道如何使两个功能一起工作,因为我想如何使所需的文本出现在单词之后
JS:
// my function
var showText = function(who, str) {
if(str !== "") {
$("#storyBoard").append("<p><span style='color:#323232;'>" + who.name + ": " + "</span>" + str + "</p>");
};
};
showText(somObj, "The text i want to append on the page when calling the function");
// the function i want to add into my first function
$(function() {
var a = new String;
a = $('.text_cont_inner').text();
$('.text_cont_inner').text('');
var c = a.length;
j = 0;
setInterval(function() {
if(j < c) {
$('.text_cont_inner').text($('.text_cont_inner').text() + a[j]);
j = j + 1;
} else {
$('.text_cont_inner').removeClass('after')
}
}, 100);
});
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>MacroG0D - My first game</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src ='Js/main.js' type="text/javascript"> </script>
</head>
<body>
<div id = "storyBoard">
<h1> Star Wars - Healing <br>The Breach:<hr></h1>
<p class="intro">A long time ago, in a galaxy far, far away</p>
<p> Welcome to the virtual pseudo-reality. Are you ready to start this journey? </p>
</div>
<input type="text" id ="myInput" placeholder="Type the command here" name="myInput" autofocus autocomplete='off'/>
<button id="btn" type="submit"> Enter </button>
</body>
</html>
显示您的html代码 – Mahi
片段仅用于可运行代码。如果您的代码仅包含JavaScript,请避免使用它们。 – 2016-11-20 19:53:59
我加了我的html代码,还有'showText'函数调用来显示我的问题。 – MacroG0D