简体   繁体   English

下拉菜单不起作用

[英]Drop down menu not work

I'm developing an easy web application, and I'm using two js libraries: dat.gui and three.js. 我正在开发一个简单的Web应用程序,我正在使用两个js库:dat.gui和three.js。

My problem is the drop down menu is locked. 我的问题是下拉菜单被锁定。 I can't open it. 我无法打开它。

// gui initialization (dat.gui)
function initGui() {

    var Options = function() {
        this.tenda = 'bar';
    };

    config = new Options();
    var gui = new dat.GUI();
    var subGui = gui.addFolder('Setting');
    subGui.open();

    // callbacks
    subGui.add( config, 'tenda', ['bar', 'pie', 'area']).
        onChange(
            function() {
                if (config.tenda === 'bar') { ... }
                else if (config.tenda === 'pie') { ... }
                else if (config.tenda === 'area') { ... }
            }
        );
};

Reading on the web, it seems to be a known issue, but in some examples, I see the drop down menus working well. 在网上阅读,这似乎是一个已知问题,但在某些例子中,我看到下拉菜单运行良好。 I'm new to js, and I thought "maybe there is some scoping issue", so I put the initialization process inside a function that does the work. 我是js的新手,我想“也许有一些范围问题”,所以我将初始化过程放在一个完成工作的函数中。 But the problem remains. 但问题仍然存在。

I'm working on Ubuntu/Chrome and Ubuntu/Firefox. 我正在研究Ubuntu / Chrome和Ubuntu / Firefox。 You could check the entire code here , where I use check boxes instead of a drop down menu. 你可以在这里检查整个代码,我使用复选框而不是下拉菜单。

I face the same problem. 我面临同样的问题。 In my code, I have changed: 在我的代码中,我改变了:

var controls = new THREE.OrbitControls(camera);

to

var controls = new THREE.OrbitControls(camera, renderer.domElement);

I face the same problem. 我面临同样的问题。 In my code, I listen the mouse click event. 在我的代码中,我听了鼠标点击事件。 and the callback function like that: 和那样的回调函数:

function onDocumentMouseDown( event ) {
    event.preventDefault();

    ... //other code
}

I found out that the problem is "event.preventDefault();", that will prevent clicking on the drop down list, so by commenting it, my problems solved. 我发现问题是“event.preventDefault();”,这会阻止点击下拉列表,所以通过评论它,我的问题就解决了。 you can also check other functions which related with mouse click event. 您还可以检查与鼠标单击事件相关的其他功能。

Making sure preventDefault is only called for mouseEvents from the drawing canvas solved the issue for me (in the Context of Three.js and using OrbitControls and a raycaster for selecting on mouseclick) 确保preventDefault仅从绘图画布中调用mouseEvent解决了我的问题(在Three.js的上下文中,使用OrbitControls和raycaster在mouseclick上选择)

function onDocumentMouseDown(event) {
  // https://stackoverflow.com/a/11562933/1497139
  var target = event.target || event.srcElement;
  var tag = target.tagName;
  if (tag!='CANVAS')
    return;
  event.preventDefault();

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

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