JavaScript OnMouseDown 图像悬停效果帮助

发布于 2024-11-01 17:29:31 字数 446 浏览 5 评论 0原文

这就是我制作的秒表(您可以此处查看)。

但是,当您尝试时,您会发现存在一些问题,而我想要实现的是...

当我将鼠标悬停在开始按钮上时,它会显示翻转,但是当我单击时,会出现停止按钮,并且当鼠标按钮抬起,停止按钮翻转/悬停图像出现。

它会按照我想要的方式进行操作,但是当您将鼠标悬停在秒表上时,时间即将过去,当我希望保留停止按钮时,就会出现开始按钮。

此外,当时间过去,光标仍然在停止按钮上时,一旦再次按下它,而不是显示开始按钮,就像我希望它仍然显示停止按钮一样。

现在我知道我必须使用 If 和 Else If 语句来实现这一点,但是我不知道如何让它发挥作用。 (我花了近 3 个小时试图找到答案,今天一整天都在享受内心的金发时刻)

任何人都可以帮忙吗?

So here's the thing I made a stopwatch (that you can view here).

However when you try it out you'll see there's some problems, and what I'm trying to achieve is...

When I hover over the start button, it's rollover shows, but when I click down the stop button appears, and when the mouse button is up the stop buttons rollover/hover image appears.

In which it does what I want it to there, but when you hover off the stopwatch when the time is going the start button appears when I want the stop button to remain.

Additionally, when the time is going, and the cursor is still on the stop button, once it's pressed again instead of showing the start button, like I want it still shows the stop button.

Now I know I haft to use the If, and Else If statements with this however I'm unaware on how to get this to work. (I've spent almost 3 hours trying to find the answer, and just having a inner blonde moment today all day)

Can anybody help???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

救赎№ 2024-11-08 17:29:31

试试这个:

    <script language="javascript">
        var started = false; 
    </script>
    <div class="start">
        <A HREF="#" onclick="started = !started;findTIME();"
        onMouseOver = "if(started){document.images['imBut'].src='images/stophover';}else{document.images['imBut'].src='images/starthover.png';}"
        onMouseOut = "if(started){document.images['imBut'].src='images/stop.png';}else{document.images['imBut'].src='images/start.png';}"
        onMouseDown = "document.images['imBut'].src='images/stop.png';"
        onMouseUp = "document.images['imBut'].src='images/stophover.png';"
        <IMG NAME="imBut" SRC="images/start.png" WIDTH="65" HEIGHT="32" BORDER="0"></A>
    </div>

Try this :

    <script language="javascript">
        var started = false; 
    </script>
    <div class="start">
        <A HREF="#" onclick="started = !started;findTIME();"
        onMouseOver = "if(started){document.images['imBut'].src='images/stophover';}else{document.images['imBut'].src='images/starthover.png';}"
        onMouseOut = "if(started){document.images['imBut'].src='images/stop.png';}else{document.images['imBut'].src='images/start.png';}"
        onMouseDown = "document.images['imBut'].src='images/stop.png';"
        onMouseUp = "document.images['imBut'].src='images/stophover.png';"
        <IMG NAME="imBut" SRC="images/start.png" WIDTH="65" HEIGHT="32" BORDER="0"></A>
    </div>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文