如何在多个地方使用Photo Sphere Viewer插件?

时间:2017-12-29 06:19:23

标签: javascript jquery html jquery-plugins

我正在使用Photo sphere插件。我想在多个地方使用该脚本。

<div class="container bs-docs-container">
<div class="row">
  <div class="col-md-6" role="main">
    <section class="bs-docs-section">
        <div id="photosphere"></div>
    </section>
  </div>
    <div class="col-md-6" role="main">
        <section class="bs-docs-section">
            <div id="photosphere1"></div>
        </section>
     </div>
</div>

var PSV = new PhotoSphereViewer({
    panorama: 'img/Bryce-Canyon-National-Park-Mark-Doliner.jpg',
    container: 'photosphere',
    caption: 'Photo',
    loading_img: 'img/photosphere-logo.gif',
    navbar: 'autorotate zoom download caption fullscreen',
    default_fov: 70,
    mousewheel: true,
    size: {
      height: 500
    }
  });   
var PSV = new PhotoSphereViewer({
    panorama: 'img/Bryce-Canyon-National-Park-Mark-Doliner.jpg',
    container: 'photosphere1',
    caption: 'Photo',
    loading_img: 'img/photosphere-logo.gif',
    navbar: 'autorotate zoom download caption fullscreen',
    default_fov: 70,
    mousewheel: true,
    size: {
      height: 500
    }
  });

我想在多个地方使用的一个脚本中添加容器:'photosphere',容器:'photosphere1',。我在下面提到了演示网址。

https://rawgit.com/saravanasksp/Updated/master/index.html

1 个答案:

答案 0 :(得分:0)

使PhotoSphereViewer分离函数并将div id作为参数传递给该函数。使用div id(容器ID)调用此函数。

function psvDivFun(idname)
{
     var PSV = new PhotoSphereViewer({
        panorama: 'img/Bryce-Canyon-National-Park-Mark-Doliner.jpg',
        container: idname,
        caption: 'Photo',
        loading_img: 'img/photosphere-logo.gif',
        navbar: 'autorotate zoom download caption fullscreen',
        default_fov: 70,
        mousewheel: true,
        size: {
          height: 500
        }
      });
}

psvDivFun('photosphere');

psvDivFun('photosphere1');
不要忘记分配&#39; idname&#39;到容器。

container: idname,