开发者

Need a conversion from Jquery to vanilla javascript

Having issues transforming this from JQuery to javascript. I have tried the document.getElementbyClassName("tile").style.left = x * tileWidth + tileDepth * z + tileOffsetLeft + "px". But it doesn't like that and gives me the error Cannot set properties of undefined (setting 'left').

export function createTiles() {
    for (let counter = 0; counter &开发者_StackOverflow社区lt; coordinates.length; counter++) {
        const coord = coordinates[counter];
        const [x,y,z] = coord;
        const image = images[counter];

        const tile = $("<div></div>")
            .addClass("tile")
            .css({
                left: x * tileWidth + tileDepth * z + tileOffsetLeft + "px",
                top: y * tileHeight + tileDepth * z + tileOffsetTop + "px",
                zIndex: z
            });
        const tileFront = $("<div></div>")
            .addClass("tileFront")
            .css({
                width: tileWidth + "px",
                height: tileHeight + "px",
                borderRadius: tileRoundness + "px"
            })
            .append(image);
        tile.append(tileFront).appendTo("#game");        
    }
} 


change .addClass("tileFront") to .classList.add("tileFront") try it

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜