Making the puzzle functional
Before writing any JavaScript code to create a functional puzzle, let's write down the features of our puzzle and see how we will achieve them.
When the page loads, an image will be displayed to the user in puzzleContainer
, and a Start button will be displayed under it. The image will actually be a collection of 16 different div elements, each having the same background image but a different background position. Using the background-position
CSS property, we will be able to display the complete image to the user. Once the Start button is clicked, we will take these 16 images and place them at random positions inside pieceBox. We will also display a 4 x 4 grid, puzzleContainer
, where any of the 16 pieces could be dropped. ...
Get Mastering jQuery UI now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.