Audio on mouseover

后端 未结 2 689
不思量自难忘°
不思量自难忘° 2020-12-17 06:53

It it working partially, but how do I get the below to work with multiple audio files:

    
    
    

    

        
相关标签:
2条回答
  • 2020-12-17 07:29

    if you don't mind using HTML5:

    HTML

    <div class="birds">
       <audio src="/sounds/bird.mp3" preload="auto"></audio>
    </div> 
    

    Javascript

    $(function(){
        var birdhover     = $('.birds');
            var birdaudio = birdhover.find('audio')[0];
    
        birdhover.hover(function(){
           birdaudio.play();
        }, function(){
           birdaudio.stop();
        });
    });
    

    http://www.w3schools.com/html5/tag_audio.asp

    0 讨论(0)
  • 2020-12-17 07:33

    updated for multiple sound files
    This is what I used before: http://plugins.jquery.com/project/sound

    Usage:

    $("#sound").sound({swf: url});
    $("#sound").load(url);
    $("#sound").play();
    $("#sound").pause();
    $("#sound").stop();
    $("#sound").volume(0-100);
    

    (taken from jQuery plugins page)

    for mouseover:

    $('#selector').mouseover(function() {
       $("#sound").play('path/to/wav/or/mp3');
    });
    
    $('#second-selector').mouseover(function() {
       $("#sound2").play('path/to/second/wav/or/mp3');
    });
    
    0 讨论(0)
提交回复
热议问题