Comments (3)
Fwiw, the width and height of cg-container
are based on the width given to cg-wrap
.
from chessground.
Oh that's interesting because i set it to 100% width and 100% height but it somehow overflows my containers, I guess ill close the issue since I can adjust it but I'm having an extremely hard time making this board responsive.
Like you can see the board doesn't really respect the parents boundaries but just procedes to overflow the container
from chessground.
Im not sure how others have done it but i got a relatively responsive board with this approach:
vue.js
mounted() {
this.calculateSquareSize();
window.addEventListener("resize", this.calculateSquareSize);
},
beforeDestroy() {
window.removeEventListener("resize", this.calculateSquareSize);
},
calculateSquareSize() {
// let width = board_space.offsetWidth - 7; // for the numbers on the side of the ground
// width -= width % 8; // fix chrome alignment errors; https://github.com/ornicar/lila/pull/3881
const boardSpace = this.$refs.boardSpace as HTMLElement;
const boardWrap = document.querySelector(".cg-wrap") as HTMLElement;
const rect = boardSpace.getBoundingClientRect();
let size = Math.min(rect.width, rect.height);
size -= 7; // adjust for borders and padding
size -= size % 8; // ensure the size is a multiple of 8
boardWrap.style.width = size + "px";
boardWrap.style.height = size + "px";
document.body.dispatchEvent(new Event("chessground.resize"));
// idk why i need to do this again, but it works it also yeets the call stack.
// Fix to resize the board when using windows maximize button
window.dispatchEvent(new Event("resize"));
},
html
<div class="board-space" ref="boardSpace">
<div class="board" ref="board"></div>
</div>
css
.board-space {
flex: 1;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
}
from chessground.
Related Issues (20)
- Pgn file download is missing extension HOT 1
- callback on square click HOT 2
- How to click a chessground piece with cypress HOT 8
- Accessability HOT 2
- Not possible to set custom premove squares
- display check *after* piece animation finishes
- Allow custom classes applied to custom squares HOT 1
- Arrow doesn't snap to valid move after mouse re-enters DOM HOT 1
- How to implement piece drag and drop feature like https://lichess.org/editor? HOT 2
- Error `Could not resolve "./package.json"` on v9.0.1 HOT 1
- Premove doesn't make a sound
- Support React chessboard implementation officially, no third party HOT 1
- Possible to drag and drop pieces off the board? HOT 4
- Click HOT 3
- [QUESTION] Is it possible to allow a player to move twice?
- Input arrows from the chessground api? HOT 1
- drag&drop stops working on mobile when "touch-action: manipulation" HOT 1
- Braked Animation when an en passant capture is made HOT 1
- Add option to show the (just-) captured piece on the chess board HOT 1
- Board editor from image HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chessground.