开发者

jQuery/PHP: sliding up even if its not :last

I want to slide up #FriendRequests (a bar) if its the last friend request the user is answering on (confirm/ignore).

When you answer confirm/ignore, it sends ajax call and on success i made this:

$('#FriendRequests:last').slideUp('slow');

But my problem is now, that even if its not the last friend request you are answering on the #FriendRequests bar is sliding up.

How should i do this, so it slides up if its the last request the user is answering on? and what code/information do you need from me, please comment, so i will provide what you need in order to help me

Thank you

My code right now:

<div class="FriendRequests" style=" font-weight: bold; background: #283b43; border-bottom: 1px dashed #719dab;">
<img src="images/NewFriend_small.png" style="float: left; margin-left: 25px; margin-right: 10px;">
Friend Requests
</div> /* i want this to go away if its the last request the user is answering on */
    <?php
        while($showW =开发者_如何转开发 mysql_fetch_array($friendsWaiting)){
        ?>
         <div id="friend<?php echo $showW['id'] ?>" style="position: relative; background: #3a5f6e;">
           <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, <?php echo $sid; ?>, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>);" style="margin-right: 45px; color: #FFF;">CONFIRM</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>, <?php echo $sid; ?>);" style="color: #ccc;">IGNORE</a>
        </div>
        <?php 
        echo "<div style='font-style: italic; font-size: 11px; width: 240px;
        position: absolute; top: 8px; left: 305px;'><a rel='facebox' href='#friendmsg'><strong>\"</strong>".substr($showW[msg], 0, 80) ."<strong>\"</strong></a>
</div>";
        echo "<div style='display: none' id='friendmsg'>$showW[msg]</div>";
        echo $user['showUR']["full_name"] . "<br>
        <span style='font-size: 12px;'> ";
         showStatus($showW["bID"]); 
         showLatestSeen($showW["bID"]);
        echo "</span><br><div class='clearfloat'></div>";
        echo "</div>";
        }
        ?>

HTML:

<div id="FriendRequests" style=" font-weight: bold; background: #283b43; border-bottom: 1px dashed #719dab;">
    <img src="images/NewFriend_small.png" style="float: left; margin-left: 25px; margin-right: 10px;">
    Vänförfrågningar
</div>

<div id="friend99" style="position: relative; background: #3a5f6e;">
    <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, 1, 99, 90);" style="margin-right: 45px; color: #FFF;">Bekräfta</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, 99, 90, 1);" style="color: #ccc;">Ignorera</a>
    </div>
    <div style='font-style: italic; font-size: 11px; width: 240px;
    position: absolute; top: 8px; left: 305px;'>
        <a rel='facebox' href='#friendmsg'><strong>"</strong><strong>"</strong>
        </a>
    </div>
    <div style='display: none' id='friendmsg'></div>
    <div style='margin-top: 5px; margin-left: 45px; margin-bottom: 5px; '>
        <span style='float: left; border: 1px dashed #CCC; margin-right: 5px;'>
            <img src='images/profileimages/noPhoto_thumb.jpg'>
        </span>
        Mads Kluge <br>
        <span style='font-size: 12px;'> 25-08-2010 kl. 20:31</span>
        <br>
        <div class='clearfloat'></div>
    </div>
</div> 

<div id="friend100" style="position: relative; background: #3a5f6e;">
    <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, 1, 100, 3);" style="margin-right: 45px; color: #FFF;">Bekräfta</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, 100, 3, 1);" style="color: #ccc;">Ignorera</a>
    </div>
    <div style='font-style: italic; font-size: 11px; width: 240px;
    position: absolute; top: 8px; left: 305px;'>
        <a rel='facebox' href='#friendmsg'><strong>"</strong><strong>"</strong></a>
    </div>
    <div style='display: none' id='friendmsg'></div>
    <div style='margin-top: 5px; margin-left: 45px; margin-bottom: 5px; '>
        <span style='float: left; border: 1px dashed #CCC; margin-right: 5px;'>
            <img src='images/profileimages/noPhoto_thumb.jpg'>
        </span>
        Ani Paltian <br>
        <span style='font-size: 12px;'> 17-08-2010 kl. 18:19</span>
        <br>
        <div class='clearfloat'></div>
    </div>
</div>​

function MeYouFriendNB(confirm, uID, fID, bID){
 var c = confirm ? 'confirm' : 'ignore';
    $.ajax({ 
       type: "POST",
       url: "misc/AddFriend.php",
    data: {
    mode: 'ajax',
            friend: c,
            uID: uID,
            fID: fID,
            bID: bID
            },
       success: function(msg){
            $('#friend'+fID).slideUp('slow');
        }
     });
}


EDIT based on your comments:

Sounds like maybe the slideUp() for #FriendRequests should trigger after the final friend has been hidden.

If so, I'd still add a class to the friend elements and do this:

success: function(msg){
    $('#friend'+fID).slideUp('slow', function() {
        if( $('div.friend:visible').length == 0 ) {
             $('#FriendRequests').slideUp('slow');
        }
    });
}


try this working ex:

just add a common class to all ur friendID div.

http://jsfiddle.net/Dhmfq/


This all depends on your code...this is just an assumption. post your code

I think you're misunderstanding :last. Last just returns the last element that matches.

You want something like

// remove row
if ( $("#FriendRequests li").length == 0 ) {
    $('#FriendRequests').slideUp('slow');
} 

again...depends on your code

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜