【问题标题】:droppable div inside iframe div in jquery uijquery ui中的iframe div内的可放置div
【发布时间】:2012-08-28 11:11:38
【问题描述】:

我们的问题: 我在 iframe 外面有一个可拖动的东西,里面有一个可放置的目标。在这里,我将 iframe 显示为包含由其 src 属性加载的 HTML 的 sn-p。

请看代码:

内部 iframe 页面 (inner_iframe.html):

<body style="cursor: auto;">
    <div id="container">
    </div>
</body> 

主页:

<div id="main">
    <iframe id="containeriframe" src="inner_iframe.html"></iframe>
</div>
    <div id="container1">
        <div class="drag" style="left: 20px;" id="lable"></div>
    </div>

JavaScript 代码:

 $("#containeriframe").load(function () {
          var $this = $(this);
          var contents = $this.contents();
          // here, catch the droppable div and create a droppable widget
          contents.find('#container').droppable({
              iframeFix: true,
              drop: function (event, ui) { alert('dropped'); }
          });
      });


$( "#lable" ).draggable({
        revert: "invalid", 
        helper: "clone",
        cursor: "move",
        iframeFix: true
    });

现在我使用 Jquery 1.8 和 Jquery UI。

所以我加载页面并尝试放入 iframe div 但没有响应,所以如何管理它。

请帮帮我....

谢谢

【问题讨论】:

    标签: javascript jquery jquery-ui jquery-ui-draggable


    【解决方案1】:

    这对我有用:

    主页:

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    
            <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js""></script>
         <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.23/jquery-ui.min.js"></script>
        <script>
            $(function () {
    
                $("iframe").load(function () {
                    var iframe = $(this).contents();
                    iframe.find('#iframe_container').droppable(
                    {
                        drop: function (event, ui) { alert('dropped'); }
                    });
                });
    
                $('#drag').draggable();
    
    
            });
        </script>
    </head>
    <body>
    
        <iframe src="iframe.html"></iframe>
    
        <div  style="width:20px; height:20px; background-color: #808080" id="drag"></div>
    
    </body>
    </html>
    

    iframe:

    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
    
        <div id="iframe_container" style=" width: 40px; height: 40px; background-color: #0094ff">
        </div>
    
    
    </body>
    </html>
    

    【讨论】:

    • 但是在 iframe 中使用这个 css。 CSS:左:300px;位置:相对;然后像 ::"" 然后试一试......你会做这个演示吗?
    【解决方案2】:

    试试这个插件http://maxazan.github.io/jquery-ui-droppable-iframe/

    <!--jquery -->
    <script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
    <!--jquery UI -->
    <script type="text/javascript" src="js/jquery-ui-1.11.4.custom.js"></script>
    <!-- jquery-ui-droppable-iframe -->
    <script type="text/javascript" src="jquery-ui-droppable-iframe.js"></script>    
    <!--Activate drag and drop zones -->
    <script type="text/javascript">
    $(function() {
        //After frame loaded
        $("#testframe").load(function() {
            //Activate droppable zones
            $(this).contents().find('.droppable').droppable({
                drop: function(event, ui) {
                    //ACTION ON DROP HERE
                }
            });
        });
    
        //Activate draggable zones
        $('.draggable').draggable({
            iframeFix: true,    //Core jquery ui params needs for fix iframe bug
            iframeScroll: true  //This param needs for activate iframeScroll
        });
    
    });
    </script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多