javascript - 在页面上放大两次后 Canvas 覆盖消失

标签 javascript jquery html css

所以我遇到了一个我不知道如何修复的奇怪错误。当我在我的网站上单击一个名为“放大”的按钮时,它会启动一个覆盖层,并且在内部有一个加载蛋白质结构的 Canvas 。但是,当我单击关闭按钮并尝试再次放大它时,它什么也没加载,我似乎无法弄清楚为什么。

示例 HTML

<!-- Expanded Canvas-->
                    <div id= "myNav" class ="overlay">
                            <a href="javascript:void[0]" class = "closebtn" onClick="closeNav()">X</a>
                            <div class = "overlay-content">
                                <div class = "fixed">
                                </div>
                                <div id = "viewer2">
                                        <canvas id = "expandedCanvas"></canvas>     
                                </div>
                    </div>  
                </div>
            </div>
<a  id = "expandImage" style = "cursor:pointer">[Enlarge]</a>
<script>

    function closeNav() {
        document.getElementById("myNav").style.width = "0%";    
        document.getElementById("sequence-label").style.display = "none";
        document.getElementById("picked-atom-name").style.display = "none";
        document.getElementById("proteinAlbum").style.display = "none";
    }

</script>

JS

function expandImage() {

expandImageButton = true;

    //Start off as default for both the buttons not showing 
show("antibodyOn", false);
show("antibodyOff", false);

//Reset the width 
document.getElementById("myNav").style.width = "100%";
viewer.requestRedraw();

viewer = pv.Viewer(document.getElementById('viewer2'), { 
    antialias : true, fog : true,
    outline : true, quality : 'high', style : 'phong',
    selectionColor : 'white', transparency : 'screendoor', 
    background : '#111215', animateTime: 500, doubleClick : null,

});

//Fit to the nav bar
viewer.fitParent();

this.value = "";
this.blur();

// Same principle as the loadFromPdb
var XHR = new XMLHttpRequest();
XHR.open("GET", urlPdb, true);
XHR.send();
XHR.onreadystatechange = function () {
    if (XHR.readyState === 4) {
        if (XHR.status === 200 || XHR.status === 0) {
         staticProteinLabel = XHR.responseText.slice(0, XHR.responseText.indexOf("\n")).substr(62, 4).trim();
         var canvasStaticLabel = document.getElementById('static-label');
         canvasStaticLabel.textContent = staticProteinLabel;
         typeOfProtein = XHR.responseText.slice(0, XHR.responseText.indexOf("\n")).substr(10, 26).trim();
         var result = XHR.responseText;
         var allLines = result.split("\n");
         var lineTwo = String(allLines[1]);
         alert(lineTwo);
         var antibodyText = "ANTIBODY";
            if (typeOfProtein === "COMPLEX (ANTIBODY-ANTIGEN)") {
                isAntibody = true;
                anitbodyOn();
                }
            else if (lineTwo.indexOf(antibodyText) ) {
                isAntibody = true;
                antibodyOn();
            }
          }
        }
    }

io.fetchPdb(urlPdb, function(s) {
  structure = s;
  mol.assignHelixSheet(structure);
  cartoon();
  viewer.autoZoom();
  });

}

所以我想知道这是否只是宽度变化的问题,它无法再次加载查看器以及如何修复它?

最佳答案

所以我能够弄清楚。 Canvas 内的数据需要销毁,所以我写了一个小函数来删除数据并清除 Canvas ,以便重新加载。

关于javascript - 在页面上放大两次后 Canvas 覆盖消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38661928/

相关文章:

javascript - $.each() 内的 "Unexpected token else"

javascript - 如何在 Select2 中先设置占位符

javascript - 如何在不缩放内容的情况下使 div 可滚动?

javascript - 在 HTML 中嵌入 jquery.tablesorter.widgets.js

javascript - 当滚动元素底部到达父元素末尾时停止 jQuery 固定位置滚动

javascript - JS包括从数组到momentjs当前日期

javascript - Jquery 文件上传不适用于 asp.net 中继器的每一行

jquery - Prototype 和 jquery 插件不能一起工作

javascript - Raphael.js : Why is the SVG positioned -0. 5px 向左?

javascript - Sails.js 如何为 Yeoman 生成的应用程序提供服务