gpt4 book ai didi

php - Javascript - 如何在轮播中添加暂停按钮?

转载 作者:行者123 更新时间:2023-11-28 02:39:12 25 4
gpt4 key购买 nike

我在 Magento 中找到了这个脚本,它正在旋转某个目录中的图像。这工作正常。但我需要在“1-6”后面添加一个“暂停”按钮。我不是 javascript 专家,所以不知道如何做到这一点。有人可以帮我解决这个问题吗?

代码:

<?php
$speed = 5000;//miliseconds
?>


<script type="text/javascript">
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];
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)
{
//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>

这就是轮播的样子:enter image description here

最佳答案

也许是这样:

<?php
$speed = 5000;//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];
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>
<button type="button" onclick="paused=true;">Pause</button>

关于php - Javascript - 如何在轮播中添加暂停按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12927829/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com