Git Product home page Git Product logo

Comments (3)

niklasf avatar niklasf commented on June 10, 2024

Fwiw, the width and height of cg-container are based on the width given to cg-wrap.

from chessground.

Hugos68 avatar Hugos68 commented on June 10, 2024

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.
image
Like you can see the board doesn't really respect the parents boundaries but just procedes to overflow the container

from chessground.

Disservin avatar Disservin commented on June 10, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.