开发者

Resizable grip icon missing for div created dynamically

I have an html page where I am experimenting with resizable and other ui features for divs created dynamically. The page shows correctly when in a local directory and accessed by IE File > Open. When I tranfer the file to the web server and access by http://localhost/file.html. The resizable grip icons aren't shown. Also, there are css styles that aren't applied.

The div is defined

       var index = getCookie("divindex");
       if (index == "" || index == null) index = 1;
       var divid = "compage"+index;
       $("#page").append('<div id="'+divid+'" class="comdiv ui-widget-content"></div>');
       $('#'+divid).append('<p class="comhdr editableText ui-widget-header">Sample'+index+'</p>');
       $('#'+divid).css('top',50);
       $('#'+divid).css('left',50);
       $('#'+divid).css('width',150);
       $('#'+divid).css('height',150);
       $('#'+divid).resizable();
       $('#'+divid).draggable();
       $('#'+divid).draggable("option", "handle", '.comhdr');
       $( '#'+divid+' p').editableText();

This also happens for a static div.

 <div id="editdiv" class="comdiv ui-widget-content" style="position: absolute; top: 150px; left: 850px; width:350px; 

height:250px; border:1px solid grey;"&开发者_如何转开发gt;
    <p id="heading" class="comhdr editableText ui-widget-header">Editable</p>
</div>

The libraries in the file are

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>  
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/jquery-ui.js"></script>
<link rel="stylesheet" href="ajax.googleapis.com/ajax/libs/jqueryui/1.8.15/themes/base/jquery-ui.css">

<link rel="stylesheet" href="http://jqueryui.com/demos/demos.css">
<style>
.comdiv { position:absolute; padding: 0.5em; border: 1px solid black}
.comhdr { text-align: center; margin: 0; cursor:move; font: 14px bold Georgia; border 1px solid grey; background: grey;}
</style>
<script>
$(function() {
    $( "#editdiv" ).resizable();
    $( "#editdiv" ).draggable();
    $( "#editdiv" ).draggable("option", "handle", '#heading');
});
</script>

Why would the behavior be different between the local file and the web server?

http://jsbin.com/awosup


If I download a copy of jquery/jquery-ui to my web server this fixes the problem. From http://jqueryui.com/download I downloaded stable version 1.8.15 UI lightness theme.


I also had the probelm that the resizable grip isn't showing up along with some other styles not applied. In my case, I found out that I had a css defined which overrode some jquery-ui styles. You can see such things e.g. in Firebug. In my case, I had defined the background for div tags which weighed heavier than the ".ui-icon-gripsmall-diagonal-se" and ".ui-icon" class style definitions.

I did not need to install a local copy of jquery on my web server. CDN version works fine now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜