简体   繁体   English

jQuery-单击下一个元素时向上滑动…仅在另一行上时

[英]Jquery - Slide up when next element is clicked…when only on a different row

I have a click function that makes a div slide down.....when i click on the next li i want the previous div to slide back up and the new div to slide down but only when its on a different row....when its on the same row I'm going to put content in the div that i want to fadeIn 我有一个单击功能,使div向下滑动.....当我单击下一个li时,我希望上一个div向后滑动,而新div向下滑动,但仅当它位于另一行时... 。当它在同一行上时,我要将内容放入我要淡入的div中

heres the fiddle im working with 我在这里与小提琴

http://jsfiddle.net/abtPH/3/ http://jsfiddle.net/abtPH/3/

heres my jQuery 这是我的jQuery

$('li').on('click', function(e){
  $(this).find('.outer').slideToggle();
  $(this).toggleClass('active', 400);
});

heres my html 这是我的html

 <ul style="list-style: none;">
   <li>
    <div style="width: 156px; height: 156px; border: solid #cfcfcf 1px; padding: 10px; text-align: center; color: #cfcfcf;"> 156px X 156px</div>

  <div class="outer">
    <div class="inner">
    </div>   
  </div>
  </li>  
<li>
<div style="width: 156px; height: 156px; border: solid #cfcfcf 1px; padding: 10px; text-align: center; color: #cfcfcf;"> 156px X 156px</div>

<div class="outer">
  <div class="inner">
  </div>   
</div>
</li>  
</ul>

I presume you're looking for something like this? 我想您正在寻找这样的东西?

$('ul').on('click', 'li:not(li.active + li)', function (e) {
    function toggle(el) {
        el.toggleClass('active', 400);
        el.find('.outer').slideToggle();
    }
    var me = $(this)
    if(me.parent().has(':animated').length == 0) {
        toggle(me.siblings('.active').andSelf());
    }
});

Demo: http://jsfiddle.net/B6TZS/ 演示: http//jsfiddle.net/B6TZS/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM