Pythagoras
How do I make an pythagoras?
Well I'm gonna build my own grid layout system! With blackjack! And hookers! #futurama. What is a pythagoras? How do you make a pythagoras? This script and codes were developed by Bramus on 23 July 2022, Saturday.
Pythagoras - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Pythagoras</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <div class="container"> <div class="box" data-width="1" data-height="3">A</div> <div class="box" data-width="2" data-height="3">B</div> <div class="box" data-width="5" data-height="3">C</div> <div class="box" data-width="1" data-height="3">D</div> <div class="box" data-width="3" data-height="4">E</div> <div class="box" data-width="3" data-height="5">F</div> <div class="box" data-width="6" data-height="2">G</div> <div class="box" data-width="3" data-height="3">H</div> <div class="box" data-width="1" data-height="4">I</div> <div class="box" data-width="3" data-height="4">J</div> <div class="box" data-width="2" data-height="3">K</div> <div class="box" data-width="3" data-height="6">L</div> <div class="box" data-width="2" data-height="5">M</div> <div class="box" data-width="1" data-height="1">N</div> <div class="box" data-width="5" data-height="4">O</div> <div class="box" data-width="2" data-height="5">P</div> </div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Pythagoras - Script Codes CSS Codes
body, html { margin: 0; padding: 0; background: #353234; min-width: 1024px;
}
.container { position: relative; width: 100%; background: lime; /*top: 50%; -webkit-transform: translateY(-50%); -ms-transform: translateY(-50%); transform: translateY(-50%);*/ min-width: 1024px;
}
.box { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; position: absolute; border: 1px solid black; background: rgba(0,0,0,0.25); opacity: 0;
}
.box--shown { transition: opacity 1s; opacity: 1;
}
Pythagoras - Script Codes JS Codes
var pythagoras = { /** * Position all boxes in the container */ positionBoxes : function($container, $boxes, numCols, numRows, heightFactor) { // Define width and height of boxes var boxSizeWidth = 100 / numCols; // var boxSizeHeight = 100 / numRows; var boxSizeHeight = ((boxSizeWidth * heightFactor) / 100 * $(window).width()); // Build empty grid to work on var grid = []; for (var i = 0; i < numRows; i++) { grid.push(new Array(numCols+1).join('0').split('')); } // Loop all boxes $boxes.each(function() { // Get the box along with it's (proportional) height and width var $box = $(this), width = $box.data('width') || 1, height = $box.data('height') || 1; // Find a place in the grid for the box and inject it there yLoop: for (var y = 0; y < numRows; y++) { xLoop: for (var x = 0; x < numCols; x++) { // Extract the cell var cell = grid[y][x]; console.log('checking cell ' + x + ',' + y + ' with value ' + cell); // Cell isn't taken yet if (cell == 0) { // Check if there's enough space on the X-axis for (var i = 0; i < width; i++) { if (grid[y][x+i] != 0) { continue xLoop; } } // Check if there's enough space on the Y-axis for (var j = 0; j < height; j++) { if (grid[y+j][x] != 0) { continue yLoop; } } // All seems ok: lock it in the grid for (var i = 0; i < width; i++) { for (var j = 0; j < height; j++) { grid[y+j][x+i] = 'X'; } } $box.css({ width: (boxSizeWidth * width) + '%', height: (boxSizeHeight * height) + 'px', left: (boxSizeWidth * x) + '%', top: (boxSizeHeight * y) + 'px' }).addClass('box--shown'); // store X and Y on box $box.data('x', x); $box.data('y', y); break yLoop; } } } }); pythagoras._fixContainerHeight($container, numCols, numRows, heightFactor); }, fixHeights: function($container, $boxes, numCols, numRows, heightFactor) { pythagoras._fixBoxesHeight($container, $boxes, numCols, numRows, heightFactor); pythagoras._fixContainerHeight($container, numCols, numRows, heightFactor); }, _fixBoxesHeight: function($container, $boxes, numCols, numRows, heightFactor) { var windowWidth = Math.max($(window).width(), $container.width()); // Fix all box heights (width goes automatically via CSS %) $boxes.each(function() { var $box = $(this), height = $box.data('height') || 1, y = $box.data('y'); var boxSizeWidth = 100 / numCols; var boxSizeHeight = ((boxSizeWidth * heightFactor) / 100 * windowWidth); $box.css({ height: (boxSizeHeight * height) + 'px', top: (boxSizeHeight * y) + 'px', }); }); }, /** * Fix the height of the container when all boxes are positioned inside it * Because we use absolute positioning, we need to do this. * @param jQuery $container The element wrapping all boxes * @param int numCols [description] * @param int numRows [description] * @param double heightFactor [description] * @return void */ _fixContainerHeight : function($container, numCols, numRows, heightFactor) { var windowWidth = Math.max($(window).width(), $container.width()); // Fix container height $('.container').css({ height: windowWidth * heightFactor * numRows / numCols + 'px' }); }
};
// Thunderbirds are go!
jQuery(function($) { // Config var numCols = 12, numRows = 13, heightFactor = 0.45, $container = $('.container'), $boxes = $container.find('.box'); pythagoras.positionBoxes($container, $boxes, numCols, numRows, heightFactor); $(window).on('resize', function() { pythagoras.fixHeights($container, $boxes, numCols, numRows, heightFactor); }); // @TODO: throttle this
})
Developer | Bramus |
Username | bramus |
Uploaded | July 23, 2022 |
Rating | 3 |
Size | 3,197 Kb |
Views | 50,600 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
CSS Revolving Door | 2,312 Kb |
Skrollr basic implementation | 2,467 Kb |
Canvas multiline fillText | 1,875 Kb |
Bouncing Ball Animation | 5,013 Kb |
Scrolling Horizontal Isotope | 2,017 Kb |
Photosphere Demo | 1,922 Kb |
Simple Flexbox Grid System | 7,705 Kb |
Simplest CSS Slideshow | 1,994 Kb |
CSS Glitch | 2,699 Kb |
Scroll Animations | 3,466 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Exploding Text | Jjmartucci | 4,749 Kb |
404 Page | Saransh | 2,666 Kb |
A Pen by Markku Lehmonen | SharpDal | 7,804 Kb |
Horizontal slider on scroll | Alojzije | 2,672 Kb |
Zeichensatz | Moklick | 2,058 Kb |
Faces SVG animation | ScavengerFrontend | 2,957 Kb |
Login-ng-modal | Heedoo | 3,566 Kb |
A form arranged using automatic placement. | Vikasford | 2,103 Kb |
SlideupBoxes | Gavra | 23,772 Kb |
Savemedia1.1 | EdsonAlcala | 2,148 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!