简体   繁体   English

放置dojo dijit.form.DropDownButton的内容?

[英]Positioning the contents of a dojo dijit.form.DropDownButton?

I have this jsfiddle where I have three buttons on the top right. 我有这个jsfiddle ,在右上角有三个按钮。

The content of the two buttons which are all the way to the right, "Basemaps" and "Legend", open toward the left as expected so they do not go out of the browser window. 一直向右的两个按钮的内容(“底图”和“图例”)按预期向左打开,因此它们不会超出浏览器窗口。 The content of the left button, "Map Overlays", opens to toward the right because there is room for it to do so. 左按钮的内容“ Map Overlays”向右打开,因为它有足够的空间这样做。

Is it possible to change the content of these DropDownButtons so that by default they all position themselves with the right side of the content aligned with the right side of the button? 是否可以更改这些DropDownButtons的内容,以便默认情况下它们都将自己定位为使内容的右侧与按钮的右侧对齐?

IE, I would like for the opened contents of left button ("Map Overlays") to position itself the same way as the opened contents of the other buttons do. IE,我希望左按钮的打开内容(“地图叠加层”)的位置与其他按钮的打开内容相同。

Fixed jsfiddle with desired functionality. 修复了具有所需功能的jsfiddle。

I've fixed this by adding a dojo.connect for the onMouseDown event of the DropDownButton. 我通过为DropDownButton的onMouseDown事件添加一个dojo.connect来解决此问题。 I calculate the new x-position for the ContentPane from the DropDownButton's x-position and width. 我从DropDownButton的x位置和宽度计算ContentPane的新x位置。 Then I find the parent node node of the ContentPane's DOM node and set its left style parameter to that new x-position. 然后,我找到ContentPane的DOM节点的父节点节点,并将其left样式参数设置为该新的x位置。

dojo.connect(dijit.byId("mapOverlayDropdown"), 'onMouseDown', function() {
    console.log("shown");

    var button = dijit.byId("mapOverlayDropdown").domNode;
    var gallery = dijit.byId("mapOverlayGallery").domNode.parentNode;

    var buttonPos = dojo.position(button, true);
    var galleryPos = dojo.position(gallery, true);

    var newX = buttonPos.x + buttonPos.w - galleryPos.w;

    gallery.style.left = newX.toString() + "px";
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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