2012-05-03 45 views

回答

1

您现在有下面的代码...

// sliding load board search option 
$(document).ready(function() { 
    $(".topMenuAction").click(function() { 
     if ($("#openCloseIdentifier").is(":hidden")) { 

       $("#slider").animate({ 
        marginTop: "-55px" //adjust as needed 
       }, 390); 


      $("#topMenuImage").html('<img src="https://lh5.googleusercontent.com/-4P1KGHJcd7w/T6MFfHRttBI/AAAAAAAACNA/JgwzfhkIrAs/w208-h208-n-k/arrow-up.png" height="50px" width="50px" alt="open" />'); 
      $("#openCloseIdentifier").show(); 
     } else { 
      $("#slider").animate({ 
       marginTop: "24px" 
      }, 350); 
      $("#topMenuImage").html('<img src="https://lh5.googleusercontent.com/-Xgkkkl6QmoM/T6MFfAqNwWI/AAAAAAAACNA/Ghf_F21rz0E/w208-h208-n-k/arrow-down.png" height="50px" width="50px"alt="close" />'); 
      $("#openCloseIdentifier").hide(); 
     } 
    }); 
});​ 

的首要问题,是你的marginTop动画就是倒退。如果你将第一个24px而不是-55px,然后第二个-55px而不是24px,就像下面的代码一样,它应该像你期待的那样行事!

// sliding load board search option 
$(document).ready(function() { 
    $(".topMenuAction").click(function() { 
     if ($("#openCloseIdentifier").is(":hidden")) { 

       $("#slider").animate({ 
        marginTop: "-55px" // Changed this to -55px 
       }, 390); 


      $("#topMenuImage").html('<img src="https://lh5.googleusercontent.com/-4P1KGHJcd7w/T6MFfHRttBI/AAAAAAAACNA/JgwzfhkIrAs/w208-h208-n-k/arrow-up.png" height="50px" width="50px" alt="open" />'); 
      $("#openCloseIdentifier").show(); 
     } else { 
      $("#slider").animate({ 
       marginTop: "24px" // Changed this to 24px 
      }, 350); 
      $("#topMenuImage").html('<img src="https://lh5.googleusercontent.com/-Xgkkkl6QmoM/T6MFfAqNwWI/AAAAAAAACNA/Ghf_F21rz0E/w208-h208-n-k/arrow-down.png" height="50px" width="50px"alt="close" />'); 
      $("#openCloseIdentifier").hide(); 
     } 
    }); 
});​ 
+0

呃。感谢您的帮助。 – PixelMuse

+0

我非常欢迎你,另一件我注意到的事情是,箭头可能会倒退给你...在这种情况下,也只是交换你的图像,即。更改-down和-down :) – Bryan

+0

我希望你能真正阅读发布的答案。在那里有评论来确定所做的更改。 – Bryan

0

您的初始状态与hidden状态不匹配;修复,it works

$(document).ready(function() { 
    $("#openCloseIdentifier").hide(); 
    $("#topMenuImage").html('<img src="https://lh5.googleusercontent.com/-Xgkkkl6QmoM/T6MFfAqNwWI/AAAAAAAACNA/Ghf_F21rz0E/w208-h208-n-k/arrow-down.png" height="50px" width="50px"alt="close" />'); 

    // Your original code... 
} 

你可能要考虑到与定义预先'<img ...>'部分的字符串变量...

0

简单;检查是(“:hidden”)返回错误的值,因为它尚未被隐藏 - 由于负溢出,它只是不可见。 add

$("#openCloseIdentifier").hide();