开发者

drag and drop with jquery and php

hy, i have a php array with the name of some images! i list all the images use this:

$files = $_SESSION['files'];
$imgid = $_POST['id'];
if ($files){
        foreach($files as $image ):
            print '<li id="liupimages">'."\n";
                print '<a href="uploads/'.$image.'"><img id="'.$imgid.'" alt="'.$image.'" src="uploads/'.$image.'"></a>'."\n";
            print "</li>\n";
        endforeach;
    print <<<JS
<script>
$(".thumbs li a").click(function(){
    var largePath = $(this).attr("href");
    $('.thumbs li').removeClass('thumbac');
    $(this).parent().addClass('thumbac');
    $("#开发者_JAVA百科largeImg").hide()
                  .attr({ src: largePath })
                  .load(function() {
                       $(this).show();
                   });
    return false;
});

</script>
JS;
} 

i use jquery-ui to drag and drop images using this function:

$(function() {
    $("#upimagesQueue").sortable({ opacity: 0.6, cursor: 'move', update: function() {
    //??                                                         
    }                                 
    });
});

after i drag and drop one image i want to be able to update the php array to! how to do this?


Use ajax:

$.get("re-arrange.php", { 'myArray[]': ['file1', 'file2']} );

http://api.jquery.com/jQuery.get/


Don't use jQuery use dom-drag it's much better and more functional.

Add this code:

<script type="text/javascript" src="http://www.dynamicdrive.com/dynamicindex11/domdrag/dom-drag.js"></script>
<script type="text/javascript">
Drag.init(document.getElementById("exampleid")); //sets the id to look for to make object draggable
</script>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜