为什么我必须在第一次点击Div两次?

时间:2014-03-24 03:27:14

标签: javascript jquery

我正在运行一个jQuery脚本,它的工作正常,但我有一些切换功能,当你点击它时滑入div。第一次你必须双击它以使其工作我很想删除它。谁知道为什么会这样?这就是我的意思 http://www.gregtaylordesignstudio.com/great-Lakes-Project/actions.html

这是脚本

    $(document).ready(function(){
      $(".inline").colorbox({inline:true, width:"50%"});
      //Example of preserving a JavaScript event for inline calls.
      $("#click").click(function(){ 
        $('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
        return false;
      });
      var slideout = $('#actionsBlurb');
      $('#dots').hide();
      $('#mapBack').delay(1000).animate({top:"45px"},800).fadeOut(400);
      $('#mapBackTop').delay(1000).fadeOut(1000);
      slideout.delay(4000).animate({ right: 175, }, { duration: 1000, easing: 'easeOutExpo'});                   
      var open = true;
      $(".close").click(function () {
        if(open === false) {
          open = true;
          slideout.animate({ top: '-170px'}, { queue: false, duration: 500 });$('#dots').fadeIn(2000); 
        }  else if(open === true) {
          open = false;
          slideout.animate({ top: 0}, { queue: false, duration: 500});$('#dots').fadeOut(1000); 
        }

      });
    })

;

1 个答案:

答案 0 :(得分:0)

var open = true;
      $(".close").click(function () {
        if(open == false) {
          open = true;
          slideout.animate({ top: '-170px'}, { queue: false, duration: 500 });$('#dots').fadeIn(2000); 
        }  else{
          open = false;
          slideout.animate({ top: 0}, { queue: false, duration: 500});$('#dots').fadeOut(1000); 
        }

      });