设置jquery ui的对话框模态宽度?

时间:2010-11-24 04:05:39

标签: jquery-ui

HI

我正在使用this demo来显示模态对话框

如果我在谷歌街景中使用它,如何设置对话框的宽度:

var point = new GLatLng(svlat, svlon);
var panoClient = new GStreetviewClient(); 
panoClient.getNearestPanoramaLatLng(point, function (newPoint) {
  if (newPoint == null) {
      alert("no panorama found for this position!!");
      return;
  }
  panoramaOptions = { latlng: newPoint };
  myPano = new GStreetviewPanorama(document.getElementById("pano"), panoramaOptions);
  $('#dialogStreetView').dialog("option", "maxWidth", 600);
  $('#dialogStreetView').dialog('open');
  GEvent.addListener(myPano, "error", handleNoFlash);
}); 

HTML:

<div id="dialogStreetView" title="Street View Provided by Google... "     style="width:300px;height:300px">
    <a id="closestreet-view" name="closestreet-view" style="cursor:pointer; text-   decoration:underline" >Close</a>
    <div name="pano" id="pano" style="width: 300px; height: 300px"></div>
</div>  

4 个答案:

答案 0 :(得分:39)

来自文档:

这应该有效:

$("#dialogStreetView").dialog( "option", "width", 460 );

答案 1 :(得分:19)

  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$("#myDialogBox" ).dialog({
  width: 500,
  autoOpen: false,
  show: {
    effect: "blind",
    duration: 1000
  },
  hide: {
    effect: "blind",
    duration: 1000
  }
}); 
$( "#myBoxOpener" ).click(function() {
  $( "#myDialogBox" ).dialog( "open" );
});
});
</script>

====== body ======

<div id="myDialogBox" title="My Dialog Box">
    <div id="myContentLayer">
    <p>My Content</p>
    </div>
</div>
<button id="myBoxOpener" class="myButton">Open Dialog Box</button>

jsFiddle Demo

答案 2 :(得分:4)

除了Porta之外,每个人都有语法错误:

$( "#selector" ).dialog( {
  width: 500
} );

取自http://api.jqueryui.com/dialog/#option-width

答案 3 :(得分:3)

只需添加宽度:500

$('#dialogStreetView').dialog( width: 500,"option", "maxWidth", 600);