0

So I've gotten half of this code to work, but I can't seem to get the rest of it going.

I can get the div to fade in, but not the image to move.

var mouse_is_inside = false;

$(document).ready(function() {
$(".how_btn").click(function() {
    var howWorks = $("#jhow_works");
    if (howWorks.is(":visible"))
        howWorks.fadeOut("fast");
    else
        howWorks.fadeIn("fast");
    return false;

    $("#spot-1").animate({ 
    marginLeft: "+=40px",
}, 2000 );

});


$("#jhow_works").hover(function(){ 
    mouse_is_inside=true; 
}, function(){ 
    mouse_is_inside=false; 
});

$("body").click(function(){
    if(! mouse_is_inside) $("#jhow_works").fadeOut("fast");
});
});

the css

#jhow_works {
display:none;
position:absolute;
width:440px;
margin:310px 150px 0 360px;
}

img#spot-1 {
position: absolute;
margin-left: 55px;
margin-top: 20px;
}

The html

    <div id="jhow_works">
    <div id="how_wrapper">
        <img id="spot-1" src="../images/spot.png" alt="" >
    </div>
</div>


        <div id="how_it_works">
        <div id="logo_how"><a class="how_btn"  href="..."><img class="how_button" src="../images/how_it_works_logo.png" alt="How it works!" ></a></div>
        <div id="text_how"><a class="big how_btn"  href="..."><strong class="big_bold_main">How</strong>&nbsp;it Works</a></div>
    </div>

I must be doing something stupid here. I appreciate any help

Thanks!

2 Answers2

4

Move your return statement to the end of the click function.

$(".how_btn").click(function() {
  var howWorks = $("#jhow_works");
  if (howWorks.is(":visible"))
    howWorks.fadeOut("fast");
  else
    howWorks.fadeIn("fast");

  $("#spot-1").animate({ 
  marginLeft: "+=40px"}, 2000 );

  return false;
});
Heather Gaye
  • 1,118
  • 1
  • 11
  • 19
1

I was going to answer with the same code as Heather has provided above so instead I will just post a link to some useful information regarding return false;. This info was provided by another Stack Overflow user in another question What does "return false;" do?

Hope this helps someone.

Community
  • 1
  • 1
ObstacleCoder
  • 160
  • 2
  • 8