0
<!doctype html>
<html>

<head>
    <meta charset="utf-8">


</head>

<body>
    <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.js"></script>
<script nomodule src="https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js"></script>
<!-- Use it like any other HTML element -->
<model-viewer src="shared-assets/models/Astronaut.glb" alt="A 3D model of an astronaut" auto-rotate camera-controls></model-viewer>
</body>

</html>

当您单击模型查看器时,会出现轮廓,我无法从model-viewer如何删除轮廓中删除它?

当您单击模型查看器时,会出现轮廓

编辑

/**
 * This is mixin function is designed to be applied to a class that inherits
 * from HTMLElement. It makes it easy for a custom element to coordinate with
 * the :focus-visible polyfill.
 *
 * @param {Function} SuperClass The base class implementation to decorate with
 * implementation that coordinates with the :focus-visible polyfill
 */
export function FocusVisiblePolyfillMixin(SuperClass) {
  var coordinateWithPolyfill = function(instance) {
    // If there is no shadow root, there is no need to coordinate with the
    // polyfill. If we already coordinated with the polyfill, we can skip
    // subsequent invokcations:
    if (
      instance.shadowRoot == null ||
      instance.hasAttribute('data-js-focus-visible')
    ) {
      return;
    }

    // The polyfill might already be loaded. If so, we can apply it to the
    // shadow root immediately:
    if (self.applyFocusVisiblePolyfill) {
      self.applyFocusVisiblePolyfill(instance.shadowRoot);
    } else {
      // Otherwise, wait for the polyfill to be loaded lazily. It might never
      // be loaded, but if it is then we can apply it to the shadow root at
      // the appropriate time by waiting for the ready event:
      self.addEventListener(
        'focus-visible-polyfill-ready',
        function() {
          self.applyFocusVisiblePolyfill(instance.shadowRoot);
        },
        { once: true }
      );
    }
  };

  // IE11 doesn't natively support custom elements or JavaScript class syntax
  // The mixin implementation assumes that the user will take the appropriate
  // steps to support both:
  return class extends SuperClass {
    // Attempt to coordinate with the polyfill when connected to the document:
    connectedCallback() {
      super.connectedCallback && super.connectedCallback();
      coordinateWithPolyfill(this);
    }
  };
}

所以我在文件名中添加了这个focus-visible.js

将此添加到 html

<body>
    <!-- The :focus-visible polyfill removes the focus ring for some input types -->
    <script src="focus-visible.js" defer></script>
    <script type="module" src="https://unpkg.com/@google/model-viewer/dist/model-viewer.js"></script>
    <script nomodule src="https://unpkg.com/@google/model-viewer/dist/model-viewer-legacy.js"></script>
    <!-- Use it like any other HTML element -->
    <model-viewer src="shared-assets/models/Astronaut.glb" alt="A 3D model of an astronaut" auto-rotate camera-controls>
    </model-viewer>
</body>

这在css中:focus-visible polyfill{ outline: none; }

难道我做错了什么?

4

4 回答 4

1

只需确保 focus-visible.js 包含在您的页面中即可。您可能从一个没有包含它的旧示例开始您的模型查看器页面。

从 repo 或此链接中获取它: https ://unpkg.com/focus-visible@5.1.0/dist/focus-visible.js

于 2020-07-17T06:23:53.563 回答
1

我将属性添加data-js-focus-visible<model-viewer>. 像这样:

<model-viewer src="myFile.glb" data-js-focus-visible></model-viewer>

之后轮廓不再显示。

如果您<model-viewer>从官方文档https://modelviewer.dev/检查主要示例中的组件,您可以看到它们使用了该data-js-focus-visible属性:

<model-viewer src="shared-assets/models/Astronaut.glb" alt="A 3D model of an astronaut" auto-rotate="" camera-controls="" data-js-focus-visible="" ar-status="not-presenting"></model-viewer>
于 2021-01-20T10:20:34.463 回答
0

似乎这是一个持续存在的问题,model-viewer因为它仍在开发中。我会在他们的github 页面上留下一些反馈,或者看看这个问题是否与你的相符。

于 2020-05-27T14:08:45.143 回答
0

需要根据模型查看器官方文档添加此脚本

<script src="./_model-viewer_ Interactive Example_files/focus-visible.js.download" defer=""></script>
于 2020-05-31T03:29:24.150 回答