Jump to content

Recommended Posts

I'm pulling pairs of sentences out of a database using php (for students I'm teaching).

 

The pairs of sentences are formatted something like this:

<p><span class="sentence">This is the primary sentence (in French).</span><br /><span class="translation">This is a translation of the sentence (in English).</span></p>

 

I'm already loading jQuery on the page (for other functionality).

 

How can I script something so that, when I roll over a 'sentence' span, the 'translation' span will fade in to visible, and will then fade out again - to invisible – when I roll off the corresponding 'sentence' span?

 

(So, to clarify, the 'translation' spans are invisible initially but become visible when the corresponding 'sentence' span is rolled over.)

 

Is it possible? Am I making sense?...

 

Be gentle... I'm brand new to javascript...

Link to comment
https://forums.phpfreaks.com/topic/257325-fading-in-a-span-on-rollover/
Share on other sites

these pages have the functions you'll want to use and examples

 

http://api.jquery.com/fadeOut/

http://api.jquery.com/fadeIn/

 

Thanks, I've already figured out now how to target *all* items with a particular class. Still some work to do before I can target individual sentence pairs, but I'm on it...

I got this nailed down nicely, even though I say so myself, with the following:

 

<script>
	$(document).ready(function() {
	  $('.answer').hide();
	  $('.main h3').toggle(
	    function() {
	      $(this).next('.answer').slideDown();
	    },
	      function() {
	      $(this).next('.answer').fadeOut();  
	      }
      	); // end toggle
	}); // end ready
</script>
</head>
	<body>
		<div class='main'>
			<h3>Me voici à Nice.</h3>
			<div class='answer'>
				<p>Here I am in Nice.</p>
			</div>
			<h3>Je m'amuse bien avec mes amies Sara et Chloë.</h3>
			<div class='answer'>
				<p>I'm really having fun with my friends Sara and Chloë.</p>
			</div>
		</div>
	</body>

 

Wow... this javascript/jQuery combination could be the catalyst for another addiction!...

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.