Hello.

There is a block with N elements and 1 block. It is necessary that when you click on this element, a block moves under it, which currently has the display property: none;

My code moves the block every time after 6 elements: http://jsfiddle.net/Qe9sS/1/

It is necessary that when clicking on the first, second, third element - the block moves under the third, when clicked on the fourth, fifth, sixth - under the sixth, and so on.

In the original version, the elements are arranged in 3 lines per line, that is, approximately in this form:

элемент №1 элемент №2 элемент №3 элемент №4 элемент №5 элемент №6 

Thank you in advance.

    1 answer 1

    If I understood correctly, then you are just too smart, here's an example:

     var $bdetail = $(".b-detail"),$links=$(".content-item > a"); $(".content-item").on('click','> a',function (event) { event.preventDefault(); var index=parseInt($links.index(this)/3+1)*3; index=index>$links.length?$links.length:index; index--; var $that=$links.eq(index); if (!$that.next().is($bdetail)) { $bdetail.stop().slideUp('fast', function () { $bdetail.slideDown('slow').insertAfter($that); }); } }); 

    http://jsfiddle.net/oceog/Qe9sS/8/

    • @eicto, thank you for your answer, but it is necessary that when you click on the first, second, third element - the block (b-detail) moved under the third, when you click on the fourth, fifth, sixth - under the sixth, and so on. That is, for example, 6 elements are arranged in two rows, with a click on the first three - it moves under the first row, the last three - under the second row. - evansive
    • @Fishy fixed, I think this time how you wanted. - zb '
    • @eicto, thank you very much! By the way, a strange feature, if you click on the 7th element - nothing happens, and if, for example, you press on 6, and after 7, then after 7 everything goes perfectly. - evansive
    • This is because in the markup it stands at the end, put the appearing element before the links in general, and everything will be fine. well, so even jsfiddle.net/oceog/Qe9sS/9 and, accordingly, if you hide it, then park where the thread is outside of the .content-item block, such as $('body').append($bdetail) ; - zb '
    • @eicto, great, thanks again! - evansive