打印

Rails中实现可拖拽控件

Rails中实现可拖拽控件

把下面的代码存为一个.rhtml文件,就可以实现简单的拖拽了
复制内容到剪贴板
代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
        <head>
        <title>title</title>
                <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
                <%= javascript_include_tag :defaults %>
                <style>
                div{
                        background-color:green;
                        color:red;
                        width:300px;
                        height:100px;
                }
                </style>
        </head>
        <body>

    <div id="dragDIV" style="cursor:move">drag</div>
        <%= javascript_tag "new Draggable('dragDIV')" %>
                 
        <div id="dragGreen" class="green box">drag</div>
        <%= draggable_element :dragGreen, :revert => true %>
                 
        </body>
</html>
First they ignore you, then they laugh at you, then they fight you, then you win.

TOP