Fix card backgroundPosition in Chrome
Apperently, in Firefox you can get the style before appending, whereas in Chrome you cannot
This commit is contained in:
parent
dd94513736
commit
fccc4e887f
13
script.js
13
script.js
@ -86,18 +86,19 @@ interact('.card-pile')
|
|||||||
// draw a new card
|
// draw a new card
|
||||||
let newCard = document.createElement('div');
|
let newCard = document.createElement('div');
|
||||||
newCard.className = "card";
|
newCard.className = "card";
|
||||||
|
// insert the card to the page
|
||||||
|
document.querySelector("#card-container").appendChild(newCard);
|
||||||
|
|
||||||
let style = window.getComputedStyle(newCard);
|
let style = window.getComputedStyle(newCard);
|
||||||
let cardNum = pile.pop();
|
let cardNum = pile.pop();
|
||||||
newCard.setAttribute('data-num', cardNum);
|
newCard.setAttribute('data-num', cardNum);
|
||||||
newCard.style.backgroundPosition = `
|
newCard.style.backgroundPositionX =
|
||||||
${(cardNum % deckWidth) * parseInt(style.getPropertyValue("width"))}px
|
(cardNum % deckWidth) * parseInt(style.getPropertyValue("width")) + "px";
|
||||||
${Math.floor(cardNum/deckHeight) * parseInt(style.getPropertyValue("height"))}px`;
|
newCard.style.backgroundPositionY =
|
||||||
|
Math.floor(cardNum/deckHeight) * parseInt(style.getPropertyValue("height")) + "px";
|
||||||
newCard.style.backgroundImage = "url('deck.png')";
|
newCard.style.backgroundImage = "url('deck.png')";
|
||||||
newCard.style.backgroundSize = `${deckWidth * 100}% ${deckHeight * 100}%`;
|
newCard.style.backgroundSize = `${deckWidth * 100}% ${deckHeight * 100}%`;
|
||||||
|
|
||||||
// insert the card to the page
|
|
||||||
document.querySelector("#card-container").appendChild(newCard);
|
|
||||||
|
|
||||||
// update deck text
|
// update deck text
|
||||||
event.target.innerHTML = `${pileName.toUpperCase()}<br>${pile.length}/${cardCount}`;
|
event.target.innerHTML = `${pileName.toUpperCase()}<br>${pile.length}/${cardCount}`;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user