[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

JQuery hover fade in/out sound

Posted on 2013-06-13
8
Medium Priority
?
735 Views
Last Modified: 2013-06-24
I have the following code that plays a sound on rollover and pauses and rewinds it on hover off. What I would like to do is fade in and fade out the sound on hover and hover off.

What do I ened to change in my code for the sound volume to increase and decrease etc?

  var waveshover = $('.wavesound');
	var wavesaudio = waveshover.find('audio')[0];
	var firehover = $('.firesound');
	var fireaudio = firehover.find('audio')[0];
	var junglehover = $('.junglesound');
	var jungleaudio = junglehover.find('audio')[0];
	
	//jungleaudio.muted = false;
	jungleaudio.volume = 0.1;
	
	//wavesaudio.muted = false;
	wavesaudio.volume = 0.1;
	
	//fireaudio.muted = false;
	fireaudio.volume = 0.5;
   
        $('#Ocean2').hover(
		function() {	
			wavesaudio.play();
        });
    
    $('#Ocean2g').hover(
		function() {},
		function () {
			wavesaudio.pause();
			wavesaudio.currentTime = 0
    });

Open in new window

0
Comment
Question by:swgdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39246657
What is the player?

jPlayer?

I suggest you try

http://api.jquery.com/animate/#step

$('#Ocean2g').animate({
  opacity: .5,
  height: '50%'
},
{
  step: function(now, fx) {
    fireaudio.volume=now
  }
});
0
 

Author Comment

by:swgdesign
ID: 39246831
There is no player involved. I am just using HTML5 and jquery.

What does the opacity and height have to do with my sound? It won't change the volume!
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39246844
Change the hover to animation and you get the step - that is what I could find.
If fireaudio.volume changes will change the sound, then that would be a way to do it

Otherwise use setInterval

.hover(function() {
   tId = setInterval(function() {
    if(fireaudio.volume) > .0 fireaudio.volume--;
    else clearInterval(tId)  },
  100);
})
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:swgdesign
ID: 39246852
OK I get that, sort of makes sense but is a bodged way to do it.

I have already tried setInterval but I could not play the sound and get the setinterval bit to work.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 39246937
So does my setInterval work better?
0
 

Author Comment

by:swgdesign
ID: 39252639
No, because I cannot get the setinterval work with the .play method when the user hovers over the trigger element.

Can you add in your code into mine so I can see how it should be structured please?
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 2000 total points
ID: 39252690
Like this?

var tId;
$('#Ocean2').hover(function() {      
  tId = setInterval(function() {
    jungleaudio.volume--;
    if (jungleaudio.volume<=0) {
      clearInterval(tId);
      wavesaudio.play();
    }
  },100);
});
0
 

Author Comment

by:swgdesign
ID: 39271532
Awesome thanks.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question