dat.GUI-寻找一种方法来锁定滑块并防止使用鼠标将值更新到dat.GUI菜单中

you*_*t13 3 javascript three.js dat.gui

我尝试实现一种防止用鼠标更新值的方法(实际上是在three.js动画开始时,通过单击按钮启动)。

目前,我有以下dat.GUI菜单:

在此处输入图片说明

单击“开始”按钮后,我想防止用户用鼠标修改参数“ Rotation x”和“ Rotation y”。

这是此菜单的代码相关部分:

// Create GUI
var gui = new dat.GUI({
      autoplace: false, 
      width: 350,
          height: 9 * 32 - 1
});

var params = {
      GreatCircle : '',
      Rotationx : torusRotationInitX,
      Rotationy : torusRotationInitY,
      StartingVector : '',
      ComponentVectorTheta : 15.0,
      ComponentVectorPhi : 15.0,
      CovariantDerivativeVector : '',
      ComponentCovariantDerivativeTheta : 15.0,
      ComponentCovariantDerivativePhi : 15.0
};

// Set parameters for GUI
gui.add(params, 'GreatCircle').name('Great Circle ');
controllerRotationx = gui.add(params, 'Rotationx', 0, 2*Math.PI, 0.001).name('Rotation x ');
controllerRotationy = gui.add(params, 'Rotationy', 0, 2*Math.PI, 0.001).name('Rotation y ');
...
Run Code Online (Sandbox Code Playgroud)

当我点击重置按钮时,我调用以下函数:

  // Reset Button
  resetButton.onclick = function ResetParameters() {

  ...

  // Reinitialize parameters into gui
  params.Rotationx = torusRotationInitX; 
  params.Rotationy = torusRotationInitY; 

  for (var i in gui.__controllers) {
     gui.__controllers[i].updateDisplay();
  }

render();

}
Run Code Online (Sandbox Code Playgroud)

我不知道控制器是否可以选择锁定这些通常会更改其值的滑块。

可能吗 ?

谢谢你的帮助。

更新1:

也许我可以将dat.GUI菜单包装到div中,并使该div不可单击,这是解决方案吗?

更新2:

我试图应用在Method中使用的方法来禁用dat.gui中的按钮?

按照此解决方案,我在之后添加了扩展名dat.gui

dat.controllers.FunctionController = (function (Controller, dom, common) {

...

});
Run Code Online (Sandbox Code Playgroud)

以下添加的代码段是:

function blockEvent(event)
{
  event.stopPropagation();
}

Object.defineProperty(dat.controllers.FunctionController.prototype, "disabled", {
  get: function()
  {
    return this.domElement.hasAttribute("disabled");
  },
  set: function(value)
  {
    if (value)
    {
      this.domElement.setAttribute("disabled", "disabled");
      this.domElement.addEventListener("click", blockEvent, true);
    }
    else
    {
      this.domElement.removeAttribute("disabled");
      this.domElement.removeEventListener("click", blockEvent, true);
    }
  },
  enumerable: true
});
Run Code Online (Sandbox Code Playgroud)

扩展代码是否位于dat.GUI源代码中?

然后,在disabled代码中设置属性“ ”,以防止用户controllerRotationx用鼠标滑动“ ”(一旦按下开始按钮):

if (animation)
controllerRotationx.__li.disabled = true;
Run Code Online (Sandbox Code Playgroud)

不幸的是,我的方法不起作用:开始动画时,我仍然可以将包含在“ controllerRotationx”中的滑块移动。

我看到上面的链接(在dat.gui中禁用按钮的方法?),这是关于按钮的,而不是关于滑块的,是否对我的情况有所改变?

我没有为滑块找到一个明确的控制器。

如果有人看到问题所在,那就太好了。

Rad*_*dio 6

我会做的。滑块不是表单元素,在传统的w3c中没有禁用的内容。幸运的是,我们可以使用指针事件并将其正确禁用,就好像它只是使用公共dat.gui属性的表单元素一样。

var speeder = menu.add(text, 'speed', -5, 5);
speeder.domElement.style.pointerEvents = "none"
speeder.domElement.style.opacity = .5;
Run Code Online (Sandbox Code Playgroud)