我写了一个HTML代码,其目的是在网站中构建一个侧面板结构,以便根据将要提供的数据显示一些图形。但是代码有问题,没有返回所需的结果。有人能看看它并提出一些改变吗。
<!-- <head> <style> body { margin: 0; } </style> <script src="//unpkg.com/3d-force-graph"></script> <!--<script src="../../dist/3d-force-graph.js"></script>--> <!-- <link rel="stylesheet" type="text/css" href="style.css" media=”scrstyle --> <!-- </head> --> --> <!DOCTYPE HTML> <head> <style> body { margin: 0; } </style> <script src="//unpkg.com/3d-force-graph"></script> <!--<script src="../../dist/3d-force-graph.js"></script>--> <meta name="viewport" content="width=device-width, initial-scale=1"> <style> body { font-family: "Lato", sans-serif; } .sidebar { height: 100%; width: 20; position: fixed; z-index: 1; top: 20; left: 20; background-color: #111; overflow-x: hidden; transition: 0.5s; padding-top: 60px; } .sidebar a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #818181; display: block; transition: 0.3s; } .sidebar a:hover { color: #f1f1f1; } .sidebar .closebtn { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; } .openbtn { font-size: 20px; cursor: pointer; background-color: #111; color: white; padding: 10px 15px; border: none; } .openbtn:hover { background-color: #444; } #main { transition: margin-left .5s; padding: 16px; } /* On smaller screens, where height is less than 450px, change the style of the sidenav (less padding and a smaller font size) */ @media screen and (max-height: 450px) { .sidebar {padding-top: 15px;} .sidebar a {font-size: 18px;} } </style> </head> <body> <meta http-equiv="Permissions-Policy" content="interest-cohort=()"> <div id="mySidepanel" class="sidepanel"> <a href="javascript:void(0)" class="closebtn" onclick="closeNav()">×</a> <a href="#">About</a> <a href="#">Services</a> <a href="#">Clients</a> <a href="#">Contact</a> </div> <div id="3d-graph"></div> <script> // Random tree function openNav() { document.getElementById("mySidepanel").style.width = "250px"; document.getElementById("mySidepanel").style.display = "block"; } /* Set the width of the sidebar to 0 (hide it) */ function closeNav() { document.getElementById("mySidepanel").style.width = "0"; document.getElementById("mySidepanel").style.display = "none"; } const N = 3; const gData = { nodes: [ { id: "id1", name: "name1", val: 1, fx: 2, fy: 2, fz: 2 }, { id: "id2", name: "name2", val: 10, fx: 0, fy: 0, fz: 0 }, { id: "id3", name: "name3", val: 20, fx: 5, fy: 5, fz: 5 }, ], links: [ { source: "id1", target: "id2" }, { source: "id2", target: "id3" }, { source: "id3", target: "id1" }, ] }; // don't display the sidepanel const Graph = ForceGraph3D() (document.getElementById('3d-graph')) .graphData(gData) .linkDirectionalArrowLength(3.5) .linkDirectionalArrowRelPos(1) .linkCurvature(0.25) .onNodeDragEnd(node => { node.fx = node.x; node.fy = node.y; node.fz = node.z; }) .onNodeClick(node => { if (node.id == "id1") { // node.fx = 10; // toggle collapse state // node.fy = 10; // node.fz = 10; // #location.href = "https://academic.oup.com/mbe/article/24/11/2385/1014692"; openNav(); } if (node.id == "id2") { // node.fx = 50; // toggle collapse state // node.fy = 50; // node.fz = 50; // location.href = "https://github.com/kcArtemis/IISC-Project/blob/main/script.js"; openNav(); } }); </script> </body>
如果问题中有任何更改,请随时更正。