3

我已经编写了一个音板。鼠标悬停在一个按钮上,单击它,就会播放特殊的声音。当鼠标悬停在按钮上时,每个按钮的图片会变为按下状态。我的问题是,一旦单击按钮#5(中间的那个),我不知道如何将图片从屏幕左侧移动到右侧 500 像素。图片就是这个 facebook 图标,就像下面的占位符代码一样!

 <!DOCTYPE html>
    <html>
     <head>
     <link rel="stylesheet" type="text/css" href="styles.css" />
 <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">


    $('#button5').click(function() {
            $('#cat').animate({
                    right: '+=500'
                    }
                    , 5000 );
                });
});
    $(document).ready(function ()
    {
        var audioon = false;

        $('.button').click(function () 
        { 
            var audioObj = $(this).find("audio");
            var audioTag = audioObj[0];
            audioTag.volume = 0.90;

            if (audioon)
            {
                audioTag.pause();
                audioon = false;

            } else {
                audioTag.play();
                audioon = true;
            }

    });
});
</script>

    <title>Square 205 Soundboard</title>
</head>
<body>
<div class="container">
<div="buttons">
<div id="cat">
<img src="http://www.avca.org/includes/media/images/facebook-icon-small.jpg">
</div>
    <div class="row">
        <div id="button1" class="button">
            <audio preload="none">
                <source src="sounds/DBZ.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button2" class="button">
            <audio preload="none">
                  <source src="sounds/GD.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button3" class="button">
            <audio preload="none">
                <source src="sounds/LeanneBoops.mp3" type="audio/mpeg">
            </audio>
        </div>
    </div>
    <div class="row">
        <div id="button4" class="button">
            <audio preload="none">
                <source src="sounds/MakeMeMoney.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button5" class="button">
            <audio preload="none">
                <source src="sounds/Meow.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button6" class="button">
            <audio preload="none">
                <source src="sounds/Yeah.mp3" type="audio/mpeg">
            </audio>
        </div>
    </div>
    <div class="row">
        <div id="button7" class="button">
            <audio preload="none">
                <source src="sounds/Dang.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button8" class="button">
            <audio preload="none">
                <source src="sounds/Benny.mp3" type="audio/mpeg">
            </audio>
        </div>
        <div id="button9" class="button">
            <audio preload="none">
                <source src="sound.mp3" type="audio/mpeg">
            </audio>
        </div>
    </div>
    <div class="row">
        <div id="button10" class="button">
            <audio preload="none">
                <source src="sound.mp3" type="audio/mpeg">
            </audio>
        </div>
    </div>

    </div>
</div>

</body>

</html>

**CSS**

    body {
    background-color: white;
}

audio {
    display: none;
}


.container {
    width:960px;
    margin:0 auto;
    background:url(buttons/frame.png) no-repeat center top;
    padding-bottom: 110px;
    padding-top: 20px;
}

.row {
    width:100%;
    text-align:center;
}

.button:hover {
    cursor:pointer;
}

.row div{
    display: inline-block;
    margin-right: 2px;
}

.button {
    height:143px;
    width:143px;
}

#button1 {
    background:url(buttons/button1.png) no-repeat;
}

#button1:hover
{
    background:url(buttons/button1p.png) no-repeat;
}

#button2 {
    background:url(buttons/button2.png) no-repeat;
}

#button2:hover
{
    background:url(buttons/button2p.png) no-repeat;
}

#button3 {
    background:url(buttons/button3.png) no-repeat;
}

#button3:hover
{
    background:url(buttons/button3p.png) no-repeat;
}

#button4 {
    background:url(buttons/button4.png) no-repeat;
}

#button4:hover
{
    background:url(buttons/button4p.png) no-repeat;
}

#button5 {
    background:url(buttons/button5.png) no-repeat;
}

#button5:hover
{
    background:url(buttons/button5p.png) no-repeat;
}

#button6 {
    background:url(buttons/button6.png) no-repeat;
}

#button6:hover
{
    background:url(buttons/button6p.png) no-repeat;
}

#button7 {
    background:url(buttons/button7.png) no-repeat;
}

#button7:hover
{
    background:url(buttons/button7p.png) no-repeat;
}

#button8 {
    background:url(buttons/button8.png) no-repeat;
}

#button8:hover
{
    background:url(buttons/button8p.png) no-repeat;
}

#button9 {
    background:url(buttons/button9.png) no-repeat;
}

#button9:hover
{
    background:url(buttons/button9p.png) no-repeat;
}

#button10 {
    background:url(buttons/button1.png) no-repeat;
}

#button10:hover
{
    background:url(buttons/button1p.png) no-repeat;
4

2 回答 2

1

CSS

#cat { position : relative; }
于 2012-11-22T07:19:25.953 回答
0

由于不包含源图像,因此测试它有点困难,而且您要完成的工作并不完全清楚,但我会试一试。您的 javascript 的第一部分存在语法错误,一个额外的 });。此外,点击处理程序应该放在 $(document).ready() 中。css 的最后一行省略了一个括号,尽管我确信在复制和粘贴过程中忘记了它。此外,Atif 是正确的 - position: relative 应该应用于动画的目标。这是重写的脚本:

<script type="text/javascript">
$(document).ready(function() 
{
    var audioon = false;

    $('.button').click(function() 
    {
        var audioObj = $(this).find("audio");
        var audioTag = audioObj[0];
        audioTag.volume = 0.90;

        if (audioon) 
        {
            audioTag.pause();
            audioon = false;

        } else 
        {
            audioTag.play();
            audioon = true;
        }

    });
    $('#button5').click(function() 
    {
        $('#cat').animate(
        {
            right : '+=500'
        }, 5000);
    });
});
</script>
于 2012-11-23T17:01:20.773 回答