2016-08-16 6 views
0

Jqueryの合計午前です。 xhtmlにサブメニューを作成しました。サブメニューから項目をドラッグするJquery

<p:panelMenu style="width:200px" id="menus"> 
       <p:submenu label="Add Control" styleClass="ctl-tiered-submenu-1" 
        rendered="true"> 
        <p:menuitem value="Bilance" actionListener="#{myIndexBean.addControl}"/> 
        <p:separator /> 
        <p:menuitem value="Average Salary" /> 
       </p:submenu> 
</p:panelMenu> 

今、私はドラッグ可能にしたいMenuItem。私はJQueryを使ってこれを作成しました:

$(".ui-panelmenu-content").draggable({revert:true }); 

今、私はドラッグ可能MenuItemを持っていますが、私は​​の外に、この要素を移動することはできません。どのようにこれを修正することができますか?

答えて

0
HTML  
<!Doctype html> 
<html> 
<body> 
    <ul> 
    <li><a href="javascript:void;" data-address="a.php">Blah</a> 
    <li><a href="javascript:void;" data-address="b.php">Blah</a> 
    <li><a href="javascript:void;" data-address="c.php">Blah</a> 
    <li><a href="javascript:void;" data-address="d.php">Blah</a> 
    <li><a href="javascript:void;" data-address="e.php">Blah</a> 
    <li><a href="javascript:void;" data-address="f.php">Blah</a> 
</ul> 
<div class="ui-widget-header"> 
<p>Drag a menu item over me!</p> 
</div> 
</body> 
</html> 


    CSS 
    ul li { 
     display:inline-block; 
     position:relative; 
     text-align:center; 
     } 
    @media screen and (min-width:480px) {ul li{width:33.33%;}} 
    @media screen and (max-width:479px) {ul li{width:50%;}} 
     @media screen and (max-width:195px) {ul li{width:100%;}} 
    ul li a { 
     display:block; 
    padding:20px 0; 
    text-decoration:none; 
    color: black; 
    text-transform:uppercase; 
     } 
    ul li:nth-child(1) a{background-color: green;} 
    ul li:nth-child(2) a{background-color: red;} 
    ul li:nth-child(3) a{background-color: #ff8400;} 
    ul li:nth-child(4) a{background-color: purple;} 
    ul li:nth-child(5) a{background-color: #49a7f3;} 
    ul li:nth-child(6) a{background-color: yellow; } 
    .ui-widget-header { 
    height:56px; 
    padding:18px 0; 
    margin:auto !important; 
    text-align:center; 
    -webkit-box-sizing: border-box; 
    -moz-box-sizing: border-box; 
     -ms-box-sizing: border-box; 
    box-sizing: border-box; 
    } 

jQueryの

$(function() { 
    $("ul li").draggable({ 
    snap: ".ui-widget-header", 
    snapMode: "inner", 
    revert: "invalid" 
    }); 
     $(".ui-widget-header").droppable({ 
     accept: "li", 
     drop: function (event, ui) { 
      location = $(ui.draggable).children('a').data('address'); 
      } 
     }); 
     $(window).resize(function() { 
     var droppable = $('.ui-widget-header'); 
       droppable.width($('li').outerWidth() - parseInt(droppable.css('borderLeftWidth'), 10) -  parseInt(droppable.css('borderRightWidth'), 10)); 
    }).resize(); 
    }); 
+0

申し訳ありませんが、私のミスは、私は外ではなく、内側のサブメニュー要素を取りたいです – DanteVoronoi

関連する問題