views:

234

answers:

2

Hi friends,

Here is my code http://jsfiddle.net/AB6J3/7/ you can see, edit, etc.

When I roll over to red border box, the orange box should slide up and at mouse out it should slide down. it works well for the other way, but when I change slideDown to slideUp, it doesnt work :/ what am I missing?

Appreciate helps.

<!DOCTYPE html>
<html>
<head>
  <style>
div#monster { background:#de9a44; margin:3px; width:80px; height:40px; display:none; float:left; position:absolute; right:10px; top:0; }

#clickk {width:40px; height:40px; background:#ccc; position:absolute; top:0; right:10px;}
</style>
  <script src="http://code.jquery.com/jquery-latest.min.js"&gt;&lt;/script&gt;
</head>
<body>

<div style="width:550px; padding:40px 0 0;margin:0 auto; border:1px solid #111; position:relative;">    
    <div id="monster"></div>
    <div id="clickk"></div><br />
    <div style="width:500px; height:300px; background-color:#ccc; margin:0 auto;"></div>
</div>

<script>
$("#clickk").hover(function () {
    if ($("#monster").is(":hidden")) {
        $("#monster").slideDown("fast");
    } else {
        $("#monster").slideUp("fast");
    }
});

</script>

</body>
</html>​
A: 

You should try the following:

$("#clickk").hover(function () {
    $("#monster").slideUp("fast");
}, function() {
    $("#monster").slideDown("fast");
});

The second argument to .hover() is the mouseout-function.

elusive
thanks for your time, but I tried that already, in that case there is no slide box at all :/
artmania
The Problem is, that the box is hidden by default. It will appear if you hover it for the first time. The only change needed is to make it visible by default.
elusive
+1  A: 

I think you're better off with some CSS tweaks here, like this:

#monster { 
    background:#de9a44;
    width:80px; 
    height:60px; 
    display:none; 
    position:absolute;
    left: 0;
    bottom: 0;
}

#clickk {
    width:80px; 
    height:60px; 
    border:1px solid #cc0001; 
    background:transparent; 
    position:absolute; 
    top:0; 
    right:10px;
}

Then jQuery like this:

$("#clickk").hover(function () {
  $("#monster").slideToggle("fast");
});​

You can test it out here. ​

Nick Craver
yes man!! i knew it was sth about css!!! thanks!
artmania
also, your js code is much more clean! thanks for great help!! appreciate. I learnt a new thing form you today. :)
artmania
@artmania - Welcome :)
Nick Craver
it works at Firefox, but not at chrome :? weird! I'm on MacOS
artmania
works at Firefox and Opera, but not working at Safari, IE and Chrome :/
artmania
error message from chrome http://img.skitch.com/20100907-pn94huqqmkhdf74hkiqwmqmndk.jpg
artmania
@artmania - sounds like you copied a weird character in there, try deleting all the spacing and trying again
Nick Craver
you are a real life-saver!!! I didn't know space would mess up with jquery code! I cleaned all spaces and it works just great now! thanks!
artmania
@artmania - welcome :) just to be clear, whatever it was - it *wasn't* a space, it's some weird character that *looked* like a space in the editor. Sometimes when copying you'll get some crazy null/weird character in there causing issues, disguised as a space :)
Nick Craver