2014-10-11 143 views
-1

我在jquery中打開菜單我希望默認狀態已關閉,但它沒有工作 它唯一的工作時,我使div顯示:塊開始,但我想開始狀態被關閉jquery向上滑動菜單asp.net

HTML:

<div class="menu"> 
    <div> 
     <div class="menu_header" id="A1" status="close"><a href="#"><img src="img/insert.jpg" id="B1" alt="" align="left" />header</a></div> 
     <div class="menu_body" style="display:none;" id="A11"><a href="#">samy</a></div> 
    </div> 
</div> 

的jQuery:

<script type="text/javascript"> 
    $(document).ready(function() { 
     /*click function starts here*/ 
     $('.menu_header').click(function() { 
      var s = $(this).attr('id'); 
      var divid = $("#" + s + "1").attr('id'); 
      var imgid = $("#" + s + " a img").attr('id'); 
      var imgsrc = $("#" + imgid + "").attr('src'); 
var status = $(this).attr('status'); 
      if (status == "close") { 
       $("#" + imgid + "").attr('src', 'img/remove.jpg'); 
       $(this).attr('status', 'open'); 
       $("#" + divid).attr("style", "display: block !important"); 
       $(this).attr('status', 'open'); 
       $("#" + s + "1").slideDown(800); 


      } 
      else if (status == "open") { 
       $("#" + imgid + "").attr('src', 'img/insert.jpg'); 
       $("#" + imgid + "").css('display', 'none'); 
       $("#" + divid).attr("style", "display: block !important"); 
       $(this).attr('status', 'close'); 
       $("#" + s + "1").slideUp(800); 

      } 

     }); 
    }); 
</script> 

CSS:

.menu{width:300px;margin-top:1px;height:auto;} 
.menu_header a{color:#faf6e0;padding-top:8px;height:40px;width:100%;display:block;padding-left:10px;background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #548975), color-stop(1, #37705a));background:-moz-linear-gradient(top, #548975 5%, #37705a 100%);background:-webkit-linear-gradient(top, #548975 5%, #37705a 100%);background:-o-linear-gradient(top, #548975 5%, #37705a 100%);background:-ms-linear-gradient(top, #548975 5%, #37705a 100%);background:linear-gradient(to bottom, #548975 5%, #37705a 100%);} 
.menu_header img{margin:1px;} 
.menu_header a:hover{cursor:point;background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #37705a), color-stop(1, #548975));background:-moz-linear-gradient(top, #37705a 5%, #548975 100%);background:-webkit-linear-gradient(top, #37705a 5%, #548975 100%);background:-o-linear-gradient(top, #37705a 5%, #548975 100%);background:-ms-linear-gradient(top, #37705a 5%, #548975 100%);background:linear-gradient(to bottom, #37705a 5%, #548975 100%);} 
.menu_body a{padding-top:1px;padding-left:10px;margin-top:1px;margin-bottom:1px;color:#5f5f5f;vertical-align:middle;height:30px;width:100%;background: #faf6e0 ;border:1px #d9c074 solid; cursor:pointer !important;} 
.menu_body a:hover{background: #e7d6a1; color:#5f5f5f;border-left: 5px #e86a6a solid;padding-left:15px; cursor:pointer;} 

PLZ我需要幫助儘快

回答

1

試試這個JS,讓我知道,如果作品。

這裏是正在運行的小提琴:http://jsfiddle.net/bw5Luug4/

<script type="text/javascript"> 
    $(document).ready(function() { 
     /*click function starts here*/ 
     $('.menu_header').click(function() { 
      var s = $(this).attr('id'); 
      var divid = $("#" + s + "1").attr('id'); 
      var imgid = $("#" + s + " a img").attr('id'); 
      var imgsrc = $("#" + imgid + "").attr('src'); 
      var status = $(this).attr('status'); 

      if (status == "close") { 
       $("#" + imgid + "").attr('src', 'img/remove.jpg'); 
       $(this).attr('status', 'open'); 
       $("#" + s + "1").slideDown(800); 

      } 
      else if (status == "open") { 
       $("#" + imgid + "").attr('src', 'img/insert.jpg'); 
       $(this).attr('status', 'close'); 
       $("#" + s + "1").slideUp(800); 
      } 

     }); 
    }); 
</script> 
+0

它的工作,但請ü可以給我這個問題 – 2014-10-11 12:50:25

+0

一點說明您沒有指定顯示屬性作爲了slideDown和效果基本show動畫就可以搞定你,更多描述 - http://api.jquery.com/slidedown/和http://api.jquery.com/slideup/ – 2014-10-11 14:24:01