我绝对不是Web编程的入门者,而且我似乎无法使爆米花示例正常工作。我正在尝试从此处的工作示例中实现它:http://jsfiddle.net/thisgeek/At3xg/
有人可以找出我做错了什么吗?请注意,以下代码中的单词未随音频及时突出显示,但在jfiddle示例中却突出显示。
谢谢!
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://popcornjs.org/code/dist/popcorn-complete.min.js"></script>
<script>
var pop = Popcorn("#greeting");
var wordTimes = {
"w1": { start: 1, end: 1.5 },
"w2": { start: 1.9, end: 2.5 },
"w3": { start: 3, end: 4 }
};
$.each(wordTimes, function(id, time) {
pop.footnote({
start: time.start,
end: time.end,
text: '',
target: id,
effect: "applyclass",
applyclass: "selected"
});
});
pop.play();
$('.word').click(function() {
var audio = $('#greeting');
audio[0].currentTime = parseFloat($(this).data('start'), 10);
audio[0].play();
});
</script>
<style>
.word {
color: red;
}
.word:hover, .word.selected {
color: blue;
cursor: pointer;
}
</style>
</head>
<body>
<audio id="greeting" src="http://dl.dropbox.com/u/17154625/greeting.ogg" controls></audio>
<div id="text">
<span id="w1" class="word" data-start="1.0">Hello</span>,
and <span id="w2" class="word" data-start="2.0">welcome</span>
to Stack <span id="w3" class="word" data-start="3.0">Overflow</span>.
Thank you for asking your question.
</div>
</body>
</html>
最佳答案
将所有自己的JavaScript代码包装在内部
$(document).ready(function() { /* your code here */ });
或将其移动到
</body>
标记之后,使其等待运行,直到HTML正文加载完毕。当您在左上角设置
onLoad
下拉列表时,jsFiddle自动执行此操作。http://api.jquery.com/ready/
关于javascript - 无法获取javascript爆米花示例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14738727/