Javascript 如何使用div it';她在吗?

Javascript 如何使用div it';她在吗?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我做了这个,你可以把洋葱从空白处拖出来,放到页面上的任何地方,但是当你点击左边的按钮时,当它所在的div的其余部分消失了。当用户将其从白色框中拖出时,如何使其不消失 我使用jQuery使其滑出滑入: $( "#button" ).click(function() { $( "#toggle" ).toggle( "slide" ); }); 要使其正常工作,请使用以下html: <button id="button">&lt;-&g

我做了这个,你可以把洋葱从空白处拖出来,放到页面上的任何地方,但是当你点击左边的按钮时,当它所在的div的其余部分消失了。当用户将其从白色框中拖出时,如何使其不消失

我使用jQuery使其滑出滑入:

    $( "#button" ).click(function() {
      $( "#toggle" ).toggle( "slide" );
    });
要使其正常工作,请使用以下html:

   <button id="button">&lt;-&gt;</button>
    <aside class="ingredients" id="toggle">
        <section class="center">
            <section class="onion" id="draggable"></section>
            <section class="butter"></section>
        </section>
    </aside>

尝试此内置JQuery选项进行拖动

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Draggable </title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery- ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

        <style>
            #draggable { width: 150px; height: 150px; padding: 0.5em; }
        </style>
        <script>
            $(function() {
            $( "#draggable" ).draggable();
        });
        </script>
    </head>
    <body>
        <div id="draggable" class="ui-widget-content">
            <p>Drag me around</p>
        </div>
    </body>
</html>

拖拉的
#可拖动{宽度:150px;高度:150px;填充:0.5em;}
$(函数(){
$(“#可拖动”).draggable();
});
把我拖来拖去

查找相关文档

尝试将
滑到一边#切换
到左侧,方法是设置其左偏移动画,而不是切换。
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Draggable </title>
        <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery- ui.css" />
        <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

        <style>
            #draggable { width: 150px; height: 150px; padding: 0.5em; }
        </style>
        <script>
            $(function() {
            $( "#draggable" ).draggable();
        });
        </script>
    </head>
    <body>
        <div id="draggable" class="ui-widget-content">
            <p>Drag me around</p>
        </div>
    </body>
</html>