我正在使用HTML5和JS开发速读模拟。
但是,我无法理解客户的期望。
我已将以下内容用于该应用。
$('#sim').each(function () {
this.contentEditable = true;
});
var go = $('#go');
var stop = $('#stop');
var wordCount = 0;
var wordCountBox = $('#wordCountBox');
var timepassed = $('#timepassed');
var textRead = $('#textRead');
go.on("click", function (e) {
e.preventDefault();
startSim();
});
function startSim() {
var speed = $('#speed').val();
var boldWords = speed / 60;
boldWords = boldWords < 1 ? 1 : Math.round(boldWords);
timeStart = $.now();
var sim = $('#sim').text();
var wordArray = sim.split(/[\s]+/);
var simWrap = $('#sim');
var arrCount = wordArray.length;
var alreadyRead = [];
for (var i = 0; i < arrCount; i++) {
(function (index) {
setTimeout(function () {
var pos = index;
if (pos < 0) {
pos = 0;
}
alreadyRead.push(wordArray[pos]);
wordArray[pos] = '<span class="grayx">' + wordArray[pos] + '</span>';
if (pos > (boldWords - 1)) {
wordArray[pos - boldWords] = wordArray[pos - boldWords].replace("x", "dim");
}
var words = wordArray.join(" ");
simWrap.html(words);
wordCount++;
if (pos == (arrCount - 1)) {
triggerDone();
}
$('#sim span:last')[0].scrollIntoView(false);
}, i * speed);
})(i);
}
// Function done
function triggerDone() {
wordCountBox.text(wordCount + ' Words Read');
var timeEnd = $.now();
var timeRes = timeEnd - timeStart;
timeRes = parseInt(timeRes);
timeRes = timeRes / 1000;
timepassed.text(" in " + timeRes + " Seconds.");
alreadyRead = alreadyRead.join("");
textRead.text(alreadyRead);
var summary = $('#summary');
summary.show();
return;
}
stop.on("click", function (e) {
e.preventDefault();
triggerDone();
});
}
#sim {
width:800px;
height:400px;
border:solid 1px #2e2e2e;
color:black;
padding:5px;
overflow-y:scroll;
border:9px outset #0ADA0A;
margin-top:1em;
font-size:16pt;
text-align:left;
background-color:white;
column-count: 2;
-moz-column-count: 2;
-moz-column-gap: 20px;
-webkit-column-count: 2;
-webkit-column-gap : 20px;
-moz-column-rule-color: #ccc;
-moz-column-rule-style: solid;
-moz-column-rule-width: 1px;
-webkit-column-rule-color: #ccc;
-webkit-column-rule-style: solid;
-webkit-column-rule-width: 1px;
}
button{
padding:10px 25px;
color:#fafafa;
transition:all 0.3s;
cursor:pointer;
}
#go{
background-color:#46A111;
border:solid 1px #46A111;
}
#go:hover{
background-color:#fafafa;
color:#46A111;
}
#stop{
background-color:#A11111;
border:solid 1px #A11111;
}
#stop:hover{
background-color:#fafafa;
color:#A11111;
}
.summary{
width:350px;
height:30px;
margin-left:12em;
background-color:rgba(0,0,0,0.1);
border:solid 1px #2e2e2e;
padding:5px;
margin-top:10px;
display:none;
border-radius: 45px;
background: #8AC007;
padding: 5px;
}
#bold{
font-weight:bold;
}
.grayx {
font-weight: 600;
}
.graydim {
color: dimgray;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="summary" id="summary">
<span id="wordCountBox"></span>
<span id="timepassed"></span>
</div>
<button id="go">START</button>
<button id="stop">STOP</button>
<input id="speed" type="number" value="120" step="10" min="0" max="1000"/>
<span for="speed">WPM</span>
<div id="sim" cols="2" rows="2"></div>
OR
http://jsfiddle.net/Darious/dcu808w1/
更新
但我的客户希望,
用两个字的光标。 1200除以2:600字。
600字除以60秒
那将是10分钟
对吗?
使用三个字的光标。
1200 div by 3 = 400 words
400 div×60秒= 6.66分钟。
当你开始工作的时候。您可以为光标时间添加一个按钮 速度。
前1秒
然后.5秒
现在。值为:
.25,.5,.75,1,1.25,1.50,2
真的,我不知道,我该怎么改变呢?
答案 0 :(得分:0)
我唯一可以理解的是:
boldWords = boldWords < 1 ? 1 : Math.floor(boldWords);
在所描述的案例中返回1(其中boldWords
以~1.67
开头),但根据客户的意愿,他希望结果为2。
只需将其更改为
boldWords = boldWords < 1 ? 1 : Math.round(boldWords);
(或使用Math.ceil
,不了解任何进一步的要求,以及是否适合他们)