开发者

Need a conversion from Jquery to vanilla javascript

开发者 https://www.devze.com 2022-12-07 21:33 出处:网络
Having issues transforming this from JQuery to javascript. I have tried the document.getElementbyClassName("tile").style.left = x * tileWidth + tileDepth * z + tileOffsetLeft + "px"

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

精彩评论

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