问题描述
我有一个脚本在网站上运行轮播。这是正在执行的脚本。我需要在其中添加一个播放/暂停按钮。用户@gskartwii在这里以添加按钮。而且我修改了代码以适应设计。
I have got a script which runs a carousel in the site. This is the script which is doing the work. And I need to add a play/pause button in there. User @gskartwii has helped me in here Javascript - How to add a pause button in carousel? to add the button. And I have modified the code to adjust with the design.
问题是暂停工作正常。但是一旦暂停,再次单击它不会恢复播放!我不是Java语言方面的专家,所以不确定我需要进行什么编程。 :/
The problem is pause is working fine. But once it's paused clicking it again is not resuming the play! I am not an expert on Javascript, so not sure what should I need to cahnge. :/
有人可以帮我吗?
这是脚本:
<?php
$speed = 500;//miliseconds
?>
<script type="text/javascript">
var paused=false;
var timeoutID;
homeTileCount = 1;
$$('.home-tile-container img').each(function(e){
$(e).writeAttribute('id','home-tile-' + homeTileCount);
$(e).addClassName('home-tile');
homeTileCount++;
});
homeTileCount--;
var homeTileRemote = $$('.home-tile-remote')[0];
//play / pause button start
homeTileRemote.insert('<div id="home-title-remote-10" class="overflow"><a href="#" onclick="if(!paused){paused=true} else{paused=false}">| |</a></div>');
//play/pause button end
for (i=homeTileCount;i>=1;i--){
homeTileRemote.insert('<div id="home-tile-remote-'+i+'" class="overflow"><a href="#" onclick="switchTile('+i+');return false">'+i+'</a></div>');
}
function switchTile(n)
{
if(!paused){
//console.log(n);
clearTimeout(timeoutID);
$$('.home-tile-container img').each(function(e){
e.removeClassName('home-tile-active');
});
$$('.home-tile-remote > div').each(function(e){
e.removeClassName('home-tile-remote-active');
});
$('home-tile-remote-'+n).addClassName('home-tile-remote-active');
$('home-tile-'+n).addClassName('home-tile-active');
next = n+1;
if (next > homeTileCount)
next = 1;
timeoutID = setTimeout('switchTile('+next+')', <?=$speed?>);}
}
switchTile(1);
setTimeout('switchTile(2)', <?=$speed?>);
</script>
推荐答案
请参考您所问的其他问题,如果您有按钮:
Referencing from other question you asked, if you have a button:
<按钮类型= button onclick = paused = true;>暂停< / button>
然后播放按钮应为
< button type =按钮 onclick = paused = false;>播放< / button>
这篇关于javascript:播放/暂停无法在轮播中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!