首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改变量属性onclick javascript

更改变量属性onclick javascript
EN

Stack Overflow用户
提问于 2020-07-09 14:45:44
回答 1查看 53关注 0票数 1

我正在尝试使用onclick元素更改javascript对象中包含的图像URL,以便可以将图像替换为不同的图像-这是一个全景图像,所以不幸的是,不是一个简单的图像更改!

目标代码为:

代码语言:javascript
复制
<div id="img-251" style="width:100%;max-width:800px;height:80vh;max-height:600px;"></div>
</div>
<script>
var viewer251 = new PhotoSphereViewer({
 container: 'img-251',
 touchmove_two_fingers: false,
 time_anim: false,
 anim_speed: '1rpm',
 caption: 'Bedroom',
 panorama: 'http://pallighting.com.au/wp-content/uploads/2020/07/website-360-test0000.jpg',
navbar: [
 'autorotate',
 'zoom',
 'caption',
 {title: 'Normal Size',className: 'sps-icon',content: '&#xe801;',onClick: function() {document.getElementById('spscontent-251').setAttribute("style","padding:10px");document.getElementById('img-251').setAttribute("style","width:100%;max-width:800px;height:80vh;max-height:600px;");viewer251.resize({width:100,height:80});}},
 {title: 'Full Size',className: 'sps-icon',content: '&#xe800;',onClick: function() {document.getElementById('spscontent-251').setAttribute("style","position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,.5);z-index: 700;");document.getElementById('img-251').setAttribute("style","width:100%;height:100%");document.getElementById('spscontent-251').setAttribute("style","max-width:100%;position: fixed;top: 0;left: 0;right: 0;bottom: 0;background: rgba(0,0,0,.5);z-index: 99999;margin: 0;width: 100%;");viewer251.resize({width:100,height:80});}}
],
lang: {
 autorotate: 'Automatic rotation',
 zoom: 'Zoom',
 zoomOut: 'Zoom Out',
 zoomIn: 'Zoom In',
 two_fingers: ['Use two fingers to navigate']
}
});

我正在尝试使用onclick图像来更改此代码中的图像。我尝试过不同的方式来写东西,例如,使用或不使用viewer251或PhotoSphereViewer变量名……

代码语言:javascript
复制
<img src="http://pallighting.com.au/wp-content/uploads/2020/06/logo.png"  onClick="viewer251.PhotoSphereViewer.panorama: 'http://pallighting.com.au/wp-content/uploads/2020/07/website-360-test0001.jpg'">

用这种方法不走运,任何帮助都将不胜感激!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-07-09 15:07:36

您可以使用setPanorama方法

代码语言:javascript
复制
<img src="http://pallighting.com.au/wp-content/uploads/2020/06/logo.png"  
      onClick="viewer.setPanorama('http://pallighting.com.au/wp-content/uploads/2020/07/website-360-test0001.jpg')">
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62808981

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档