如何将播放和暂停键放入同一个按钮? [英] How to put play and pause keys into the same button ?

查看:352
本文介绍了如何将播放和暂停键放入同一个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅使用javascript代码将播放和暂停键放入图库中的相同按钮?当我按下播放按钮时,幻灯片应该开始,并且开始按钮也应该更改为暂停按钮。然后,当我按下暂停按钮时,图像幻灯片显示必须暂停,并将按钮更改回播放按钮。



有人请帮忙!

解决方案

在这种情况下,您应该尝试切换图像按钮。

请参考以下链接:

切换按钮演示 [ ^ ]

制作用于切换图像的JS按钮点击 [ ^ ]

如何你创建了一个切换按钮吗? [ ^ ]

JavaScript切换图像由clic Img上的国王 [ ^ ]





--Amit


这很容易通过切换( v。 切换 [ ^ ])。这实质上意味着我们不断切换按钮的语义。在这种情况下,二进制开关(因此是playpause的布尔值)就足够了。在更精细的场景中,可能需要两个以上的状态。下面是播放和暂停功能之间(二进制)切换的代码:



 <   html  >  
< head >
< script language = text / javascript >
//以Play作为第一个按钮状态开始
var playpause = true;
< / script >
< / head >
< body >
< div id = < span class =code-keyword> container >
< 按钮 id = playpause type = button 名称 = playButton onclick = setPlayPause() > 播放< / button >
< < span class =code-leadattribute> / div >
< / body >
< script language = text / javascript >
function setPlayPause()
{
//这里我们将playpause从true切换为false,反之亦然
playpause =!playpause;
if(playpause)
{
document.getElementById(playpause)。value =Play;
alert(画廊已暂停!);
//而不是警告声明你实际上会在这里暂停图库
}
其他
{
document.getElementById(playpause)。value =暂停;
alert(画廊正在播放!);
//而不是警告声明,你可以在这里放置代码来启动画廊播放
}
}
< / script >
< / html >





问候,



- Manfred

How to put play and pause keys into the same button in an image gallery using javascript codes only? When I press the play button the slideshow should get started and the start button should also be changed to pause button. Then when I press the pause button the image slideshow must get paused and the buttone be changed back to play button.

Somebody please help!

解决方案

In this condition you should try with toggle image button.
Refer the links below:
Toggle Button Demonstration[^]
Making JS buttons that toggle their image on click[^]
How do you create a toggle button?[^]
JavaScript Toggle Image by clicking on Img[^]


--Amit


This is easily achieved by toggling (v.: to toggle[^]). This essentially means that we constantly switch the semantic of the button. In this case a binary switch (thus the boolean value of playpause) will suffice. In more elaborate scenarios there might be a need for more than two states. Here is the code that does the (binary) toggle between play and pause functionality:

<html>
<head>
<script language="text/javascript">
    // Starting with "Play" as the first button state
    var playpause = true;
</script>
</head>
<body>
<div id="container">
<button id="playpause" type="button" name="playButton" onclick="setPlayPause()">Play</button>
</div>
</body>
<script language="text/javascript"> 
function setPlayPause()
{
    // Here we toggle playpause from true to false and vice versa
    playpause = !playpause;
    if(playpause)
    {
        document.getElementById("playpause").value = "Play";
        alert("Gallery has been paused!");
        // Instead of the alert statement you would actually do the pausing of the gallery here
    }
    else
    {
        document.getElementById("playpause").value = "Pause";
        alert("Gallery is now playing!");
        // Instead of the alert statement you would place the code here that would start the gallery playing
    }
}
</script>
</html>



Regards,

— Manfred


这篇关于如何将播放和暂停键放入同一个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆