Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
jQuery, slide down when mouseover then back
Old 03-12-2009, 10:02 AM jQuery, slide down when mouseover then back
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
I'd like to have jQuery toggle the visibility of a div when the mouse is over the current <tr> and then toggle back to hidden when the mouse is no longer over it.

What I currently have is:

HTML Code:
<tr onmouseover="$('#msgtxt1').show('fast');changeRow(this, true);" onmouseout="$('#msgtxt1').hide('fast');
changeRow(this, false);">
<td><a href="messages/view/6660/" onclick="jumpTo('messages/view/6660/');" style="display: block;">Re: Friend Invite from IceCube</a>
<div class="smallertext" style="display: none;" id="msgtxt1">Some text test..</div>
</td>
</tr>
But this is terribly flawed, because whenever I put the mouse over something in between the <tr> such as text or img, etc, it toggles back to hidden, then starts jiggling about crazily... Any suggestions?
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
 
Register now for full access!
Old 03-12-2009, 11:22 AM Re: jQuery, slide down when mouseover then back
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Forget about all that. Use jQuery's hover function, along with the slideUp and slideDown methods. For one thing, you should put an ID on the <tr>, or have some way of identifying it.

Code:
$(document).ready(function() {
$("tr#unique").hover(function() {
     $("#msgtxt1").slideDown(400);
}, function() {
     $("#msgtxt1").slideUp(400);
});
});
In general, you should shy away from having inline behaviors. Just like CSS is kept in a seperate place, so should JavaScript events. Plus, if you're using jQuery, you should be taking advantage of its advanced event scheme.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-12-2009, 01:16 PM Re: jQuery, slide down when mouseover then back
Galaxian's Avatar
Dingleberry!

Posts: 825
Name: Rich
Location: United Kingdom
Trades: 0
What about for multiple TR's?

#tr1
#tr2
#tr3

Also within the tr1, tr2, etc, is tr1 = <div id="txtmsg1"> tr2 = <div id="txtmsg2"> etc that I want revealing.

It's dynamically generated with php while from mysql db.
Also what am I doing wrong here

HTML Code:
var inprog = 0;
$(document).ready(function() {
if(inprog == 0) {
    $("tr#unique1).hover(function() {
     $("#msgtxt1).slideDown(400);
     inprog = 1;
}, function() {
     $("#msgtxt1).slideUp(400);
     inprog = 0;
});
}
});
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by Galaxian; 03-12-2009 at 01:37 PM..
Galaxian is offline
Reply With Quote
View Public Profile Visit Galaxian's homepage!
 
Old 03-12-2009, 01:38 PM Re: jQuery, slide down when mouseover then back
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Leave the ids on the <tr> and use a common class for the <div> nested within it. Put an ID on the table that contains the <tr>s.

Code:
$(document).ready(function() {
$("#mytableid tr").hover(function() {
     $("#" + this.id + " div.my-class").slideDown(400);
}, function() {
     $("#" + this.id + " div.my-class").slideUp(400);
});
});
Or, if it is the only <div> that is the child of the <tr> you could forget the class altogether, and just target it as $("#" + this.id + " div")

***EDIT***
btw, after a second glance at your code, I see you need to change the "inprog" variable as a callback to the slideUp/slideDown when hovering off, because the way you're doing it, it will be executed before the animation is complete. Also, you need to nest the if() inside the first hover function, not outside the event. So:

Code:
$(document).ready(function() {
    var inprog = 0;
        $("tr#unique1").hover(function() {
         if (inprog == 0) {
             inprog = 1;
             $("#msgtxt1").slideDown(400);
         }
    }, function() {
         $("#msgtxt1").slideUp(400, function() {inprog = 0;});
    });
});
Also, you dropped some quotation marks in your example, which made the code invalid.

You'll have to combine the two ideas I gave you, because on the second example, all I did was edit the code you gave. Note that I put the variable declaration "inprog" inside of the $(document).ready(), which I think is better, since it stays local to that namespace.
__________________
Join me on
Please login or register to view this content. Registration is FREE

Last edited by wayfarer07; 03-12-2009 at 02:00 PM..
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 03-12-2009, 01:53 PM Re: jQuery, slide down when mouseover then back
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
hey, I fixed a mistake on the second code example above. Take another look at it.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Reply     « Reply to jQuery, slide down when mouseover then back
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.18471 seconds with 12 queries