Skip to content

Commit 59ea297

Browse files
committed
Make robot animation images load properly in /code sandbox
1 parent 987e689 commit 59ea297

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

code/animatevillage.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@
3333
this.node = outer.appendChild(doc.createElement("div"))
3434
this.node.style.cssText = "position: relative; line-height: 0.1; margin-left: 10px"
3535
this.map = this.node.appendChild(doc.createElement("img"))
36-
this.map.src = "img/village2x.png"
36+
let imgPath = "img/"
37+
if (/\/code($|\/)/.test(outer.ownerDocument.defaultView.location)) imgPath = "../" + imgPath
38+
console.log(outer.ownerDocument.defaultView.location.toString(), /\/code($|\/)/.test(outer.ownerDocument.defaultView.localation), imgPath)
39+
this.map.src = imgPath + "village2x.png"
3740
this.map.style.cssText = "vertical-align: -8px"
3841
this.robotElt = this.node.appendChild(doc.createElement("div"))
3942
this.robotElt.style.cssText = `position: absolute; transition: left ${0.8 / speed}s, top ${0.8 / speed}s;`
4043
let robotPic = this.robotElt.appendChild(doc.createElement("img"))
41-
robotPic.src = "img/robot_moving2x.gif"
44+
robotPic.src = imgPath + "robot_moving2x.gif"
4245
this.parcels = []
4346

4447
this.text = this.node.appendChild(doc.createElement("span"))

0 commit comments

Comments
 (0)