简体   繁体   中英

jQuery UI Selectable not working with div (resizable & draggable)

I have some div's and have applied resizable & draggable methods to it. But when i apply the selectable method, it does not emit the "ui-selected" into the class of the DIV.

Pls suggest the workaround for this problem.

Below is the code:-

<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.8.20.custom.min.js" type="text/javascript"></script>
<link href="development-bundle/themes/base/jquery.ui.resizable.css" rel="stylesheet" type="text/css" />
<link href="development-bundle/themes/base/jquery.ui.theme.css" rel="stylesheet" type="text/css" />

<style type="text/css">
    .dragClass {
            font-family: Tahoma, sans;
            color: black;
            background: orange;
            border: 1px solid orange;
            width: 10em;
            height:auto;
            padding: 0.5em;
        }

    textarea {
            font-family: inherit;
            color: inherit;
            background: transparent;
            border: 0;
            width: 100%;
            height: 100%;
            resize: none;
        }
</style>

<script type="text/javascript" language="javascript">
    $(function () {
        $(".dragImgClass").draggable({ delay: 100, containment: "#ParentDIV", scroll: false });
        $(".dragClass").draggable({ delay: 100, containment: "#ParentDIV", scroll: false });
        $(".dragClass").resizable();
        $(".dragClass").selectable();

        $(".dragClass").on("click", function (event) {
            // Don't do anything if already editing                
            if ($(this).find("textarea").length) return;

            var $this = $(this); //get current obj.

            // Replace paragraph with textarea
            var $p = $this.find("p");
            var $txtar = $('<textarea/>').val($p.text());
            $p.replaceWith($txtar);
            $txtar.focus();                
        });

        $(".dragClass").on("blur", "textarea", function () {
            // Replace textarea with paragraph
            var $txtar = $(this);
            var $p = $('<p/>').text($txtar.val());
            $txtar.replaceWith($p);
        });

    });  //End of DOM Ready

    function getHTML() {
        var dv = $('#ParentDIV');
        var dvCont = $('#dvHtml');
        dvCont.css('border','2px solid red').text(dv.html());
    }

</script>

Below is the HTML Content:-

<input id="Btn1" type="button" onclick="getHTML();" value="Extract HTML" />
<div id="dvHtml"></div>
<br /><br />
   <div id="ParentDIV" style="margin-left:200px; width:800px; height:500px; background:lightgray;">                    
       <div class="dragClass"><p>Drag me around!</p></div>
       <br /><br />
       <div class="dragClass"><p>Drag me around! also</p></div>        
       <br /><br />
       <img class="dragImgClass" src="logo3.JPG" />
       <br /><br />
       <img class="dragImgClass" src="logo4.JPG" />        
   </div>

Here is jsFiddle of my problem

i can see in firebug that your Selectable div emits proper css like this "dragClass ui-draggable ui-resizable ui-selectable" inspect it in firebug/IE developer tools or any other tool it is there here is a jsfiddle to your problem i can see the selectable class applied to the div clearly in firebug.

EDIT

to disable draggable & resizable you can do it like

$('.dragclass').draggable( 'disable' );
$('.dragclass').resizable( 'disable' );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM