jQueryUI显示/隐藏子节点的动画问题

时间:2012-02-29 20:19:13

标签: css jquery-ui show-hide

我遇到了jQueryUI的show()/ hide()函数问题。它们基本上在动画期间停用我的CSS。

jsFiddle链接:http://jsfiddle.net/UBATE/1/

根据API:

http://docs.jquery.com/UI/Effects/Drop

我已经构建了以下功能:

updateTeamLists = function(args) {
    // fade out -> rebuild the content -> fade in

    $("#team1, #team2").hide("drop", {"direction": "right"}, 600, function() {
        rebuildTeamLists(args); 
        $(this).show("drop", {"direction": "right"}, 600);  
    });     
};

子DOM节点似乎在动画开始时丢失了所有CSS属性,即它们停止浮动(或丢失其内联块显示)并且它们的背景立即消失。但是,动画和淡出文本的工作正常。

HTML DOM结构:

<div id="teams">
   <div id="team1">
      <ul>
         <li>Player 1</li>
         <li>Player 2</li>
         <li>Player 3</li>
         <li>Player 4</li>
         <li>0 Pts</li>
      </ul>
   </div>
   <div id="team2">
      <ul>
         <li>Player 5</li>
         <li>Player 6</li>
         <li>Player 7</li>
         <li>Player 8</li>
         <li>0 Pts</li>
      </ul>
   </div>
</div>

CSS:

#content > #teams {
    margin-top: 10px;
    padding: 5px 5px 5px 22px;
    width: 650px;
    border: 2px solid #bfbfbf;

    -webkit-border-radius: 10px;
    -moz-border-radius: 10px;
    border-radius: 10px;

    box-sizing: border-box; 
    -moz-box-sizing:border-box;
}

#content > #teams > div {
    margin-top: 5px;
    display: block;
    height: 28px;
}

#content > #teams > div:first-child {
    opacity: 1.0;   
}

#content > #teams > div:last-child {
    opacity: 0.6;
}

#content > #teams > div > ul > li {
    height: 25px;
    width: 125px;
    border-width: 1px;
    border-style: solid;
    margin-left: 5px;   
    display: inline-block;
}

#content > #teams > div > ul > li:first-child {
    -webkit-border-top-left-radius: 20px;
    -webkit-border-bottom-left-radius: 20px;
    -moz-border-radius-topleft: 20px;
    -moz-border-radius-bottomleft: 20px;
    border-top-left-radius: 20px;
    border-bottom-left-radius: 20px;
}

#content > #teams > div > ul > li:last-child {
    -webkit-border-top-right-radius: 20px;
    -webkit-border-bottom-right-radius: 20px;
    -moz-border-radius-topright: 20px;
    -moz-border-radius-bottomright: 20px;
    border-top-right-radius: 20px;
    border-bottom-right-radius: 20px;

    width: 50px !important;
}

#content > #teams > #team1 > ul > li {
    background: rgb(229,130,130); /* Old browsers */
    background: -moz-linear-gradient(top, rgb(229,130,130) 0%, rgb(216,43,43) 51%, rgb(232,153,153) 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgb(229,130,130)), color-stop(51%,rgb(216,43,43)), color-stop(100%,rgb(232,153,153))); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, rgb(229,130,130) 0%,rgb(216,43,43) 51%,rgb(232,153,153) 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, rgb(229,130,130) 0%,rgb(216,43,43) 51%,rgb(232,153,153) 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, rgb(229,130,130) 0%,rgb(216,43,43) 51%,rgb(232,153,153) 100%); /* IE10+ */
    background: linear-gradient(top, rgb(229,130,130) 0%,rgb(216,43,43) 51%,rgb(232,153,153) 100%); /* W3C */
    border-color: rgb(229,130,130);

    text-align: center;
    padding-top:3px;
}

#content > #teams > #team2 > ul > li {
    background: #b3dced; /* Old browsers */
    background: -moz-linear-gradient(top, #b3dced 0%, #29b8e5 50%, #bce0ee 100%); /* FF3.6+ */
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#b3dced), color-stop(50%,#29b8e5), color-stop(100%,#bce0ee)); /* Chrome,Safari4+ */
    background: -webkit-linear-gradient(top, #b3dced 0%,#29b8e5 50%,#bce0ee 100%); /* Chrome10+,Safari5.1+ */
    background: -o-linear-gradient(top, #b3dced 0%,#29b8e5 50%,#bce0ee 100%); /* Opera 11.10+ */
    background: -ms-linear-gradient(top, #b3dced 0%,#29b8e5 50%,#bce0ee 100%); /* IE10+ */
    background: linear-gradient(top, #b3dced 0%,#29b8e5 50%,#bce0ee 100%); /* W3C */
    border-color: rgb(179,220,237);

    text-align: center;
    padding-top:3px;
}

不幸的是我无法在线托管代码以便进行演示,所以我发布了我得到的任何内容。我使用的是Google Chrome 17.0.963.56和Firefox 10.0.2。

我经常在向脚本添加jQueryUI效果时遇到问题,最终没有添加它们。虽然可能存在一些阻止其工作的技巧/错误(例如,如果您的DOM节点没有类属性,则toggleClass动画将无效)。

我错过了什么吗?如何解决方法,我是否必须遍历所有子节点?

提前致谢!

哈尔蒂

1 个答案:

答案 0 :(得分:1)

Jquery UI将在受影响的元素下添加一个额外的div。例如:

<div id="team1">
<ul>
  ...
<ul>
</div>

当效果应用时,结构将为:

<div id="team1">
<div class="jquery-ui something-else">
<ul>
  ...
</ul>
</div>
</div>

解决方案不是使用直接子选择器“&gt;”。请参见示例here。您可以将其与您的版本进行比较:)

相关问题