2012-04-04 64 views
0

我想製作一個菜單,從右到左滑動一個h2標題,並且當它完成從上到下的信息。如果在菜單已經存在的情況下點擊不同的選項,則首先如上所述上升然後離開其他。所以主要的問題是,在某些方面需要出現2個信息而不是1個信息,我無法想象如何去做,所有信息都是一個接一個地執行。如果使用回調,一些文字會出現兩次或更多次......流暢的菜單出現

$("a[rel~='showinfo']").click(function() { 
    var info_id = $(this).attr('id');//getting needed id from menu to show info 

    if($('.info_name').is(':visible'))//if already exists - removing 
    remove_contact(); 

    for(i=0; i<contact_status.length; i++){//checking all array for item 
    if(info_id == contact_status[i]){//if item exist 
     create_contact(i);//putting it in 
     //here starts problems.... 
     $('#info_name'+i).show("slide", {direction: "right"}, 1000, function(){ 
      $('#info_info'+i).show("slide", {direction: "up"}, 1000); 
     }); 
    } 
    } 
//$('.info_name').show("slide", {direction: "right"}, 1000); 
//$('.info_info').show("slide", {direction: "up"}, 1000); 

}); 

function create_contact(id){ 
    $('.third').append('<div class="showinfo"><h2 id="info_name'+id+'" class="info_name">'+contact_name[id]+'</h2><span class="info_info" id="info_info'+id+'">lol</span></div>') 
} 

function remove_contact() { 
    $('.info_name').hide("slide", {direction: "right"}, 1000); 
    $('.showinfo').remove(); 
} 

回答

0
for(i=0; i<contact_status.length; i++){//checking all array for item 
    if(info_id == contact_status[i]){//if item exist 
     (function (idx) { // use a Anonymous funciton 
      create_contact(idx);//putting it in 
      //here starts problems.... 
      var; 
      $('#info_name'+idx).show("slide", {direction: "right"}, 1000, function(){ 
       $('#info_info'+idx).show("slide", {direction: "up"}, 1000); 
      }); 
     })(i); 
    } 
    } 

啊,我犯了一個錯誤......這個時候應該是正確的

+0

#info_name和#info_info是不同的。 2個不同的元素。首先需要出現。 – NoNameZ 2012-04-04 15:20:58