Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Вывод № позиции при перемещение элемента (https://javascript.ru/forum/jquery/57139-vyvod-pozicii-pri-peremeshhenie-ehlementa.html)

Arx777 21.07.2015 15:31

Вывод № позиции при перемещение элемента
 
Не могу придумать способ для вывода номераци позиции (точнее могу, но не универсальный) элемента при перемещение jquery ui sort.
Т.е. если мы перетащим 1 элемент между 3 и 4, чтоб в alert вывилось (3-номер позиции: так как 2 и 3 элемент теперь над ним)



<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Sortable - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <style>
        #one {color: red}
        #two {color: green}
        #three{color: blue}
        #four{color: violet}
    </style>
<script>
$(function() {
            $( "tbody" ).sortable();
            $( "tbody" ).disableSelection();
        });
</script>
</head>
<body>
<table>
    <tbody>
    <tr id="one">
        <td>1</td>
    </tr>
    <tr>
        <td id="two">2</td>
    </tr>
    <tr id="three">
        <td>3</td>
    </tr>
    <tr id="four">
        <td>4</td>
    </tr>
    <tbody>
</table>
</body>
</html>

рони 21.07.2015 15:45

Arx777,
jQuery UI Sortable сохранение порядока сортировки при перезагрузке

Arx777 21.07.2015 15:45

Если кому интересно, то вот решение

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Sortable - Default functionality</title>
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
    <script src="//code.jquery.com/jquery-1.10.2.js"></script>
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
    <style>
        #one {color: red}
        #two {color: green}
        #three{color: blue}
        #four{color: violet}
    </style>
    <script>
        $(function() {
            $( "tbody" ).sortable();
            $( "tbody" ).disableSelection();
        });
    </script>
</head>
<body>
    <span>Click!</span>
    <table>
        <tbody>
        <tr id="one">
            <td>1</td>
        </tr>
        <tr>
            <td id="two">2</td>
        </tr>
        <tr id="three">
            <td>3</td>
        </tr>
        <tr id="four">
            <td>4</td>
        </tr>
        <tbody>
    </table>
    <script>
        $( "tr" ).click(function() {
            var index = $( "tr" ).index( this );
            $( "span" ).text( "That was div index #" + index );
        });
    </script>
</body>
</html>

Arx777 21.07.2015 15:47

рони,Благодарю за ваш вариант.:)


Часовой пояс GMT +3, время: 07:44.