Randomly shuffle colors
How do I make an randomly shuffle colors?
My brother asked me if I could help him randomly change the background colors on the posts on a tumblr he's working on. Good challenge for me. Each post has the class of post. Then there are classes in the css that have background colors assigned to them. These class names are added to an array in JS, shuffled on load and then added to each post on the page. Fun.. What is a randomly shuffle colors? How do you make a randomly shuffle colors? This script and codes were developed by Cory on 13 December 2022, Tuesday.
Randomly shuffle colors - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Randomly shuffle colors</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ * { box-sizing: border-box;
}
.post { max-width: 800px; padding: 24px; margin: 10px; color: #444; background: #efefef; /* default color */
}
/* colors or themes or stuff */
.rad { background: #e5dbf2;
}
.neat { background: #e9dbd5;
}
.gnarly { background: #eafdf8; /*color: #fff; you could change other stuff if needed */
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div class="post"> <h2>Check this out</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati quos nulla repudiandae labore magnam aut et sunt quas incidunt rem quis excepturi quidem soluta commodi iure aperiam pariatur temporibus ipsum.</p>
</div>
<div class="post"> <h2>Hey, bro.</h2> <p>Consectetur adipisicing elit. Obcaecati quos nulla repudiandae labore magnam aut et sunt quas incidunt rem quis excepturi quidem soluta commodi iure aperiam pariatur.</p>
</div>
<div class="post"> <h2>Pretty Sweet</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati quos nulla repudiandae labore magnam aut et sunt quas incidunt rem quis excepturi quidem soluta commodi iure aperiam pariatur temporibus ipsum.</p>
</div>
<div class="post"> <h2>Pretty Lame</h2> <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Obcaecati quos nulla repudiandae labore magnam aut et sunt quas incidunt rem quis excepturi quidem soluta commodi iure aperiam pariatur temporibus ipsum.</p>
</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>
Randomly shuffle colors - Script Codes CSS Codes
* { box-sizing: border-box;
}
.post { max-width: 800px; padding: 24px; margin: 10px; color: #444; background: #efefef; /* default color */
}
/* colors or themes or stuff */
.rad { background: #e5dbf2;
}
.neat { background: #e9dbd5;
}
.gnarly { background: #eafdf8; /*color: #fff; you could change other stuff if needed */
}
Randomly shuffle colors - Script Codes JS Codes
$(function() { var classList = ["rad","neat","gnarly"]; // 'borrowed' from http://stackoverflow.com/questions/2450954/how-to-randomize-shuffle-a-javascript-array function shuffle(array) { var currentIndex = array.length, temporaryValue, randomIndex; // While there remain elements to shuffle... while (0 !== currentIndex) { // Pick a remaining element... randomIndex = Math.floor(Math.random() * currentIndex); currentIndex -= 1; // And swap it with the current element. temporaryValue = array[currentIndex]; array[currentIndex] = array[randomIndex]; array[randomIndex] = temporaryValue; } return array; } shuffle(classList); $('.post').each(function(i) { var idx = i % classList.length; $(this).addClass(classList[idx]); });
});
Developer | Cory |
Username | uniqname |
Uploaded | December 13, 2022 |
Rating | 3 |
Size | 2,806 Kb |
Views | 20,240 |
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 |
X-Picture tag | 2,573 Kb |
A content slider | 2,374 Kb |
Paper like dialog compoent | 4,701 Kb |
Javascript Digital Clock Example | 1,797 Kb |
PictureTime | 3,565 Kb |
JS REPL | 5,216 Kb |
Digital Clock | 1,897 Kb |
A Pen by Cory | 3,306 Kb |
CSA-React POC | 5,660 Kb |
Hover activated accordian with default state | 1,946 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 |
Portfolio page | Bhavya_j | 2,804 Kb |
Awesome | Samarthpd | 2,901 Kb |
Responsive Minimal Blog Layout | Hackthevoid | 5,261 Kb |
Pruebas de d3.js | Juanmanuelcarnerero | 2,485 Kb |
Mobile Nav Menu | AliKlein | 4,745 Kb |
Dice | Fraina | 5,026 Kb |
Login with flip 3d animation | Mariusbalaj | 3,014 Kb |
Dribbble Template | ExtremelyGinger | 2,204 Kb |
Blog | Rottingroom | 1,430 Kb |
Adding and Removing Element | Accimeesterlin | 2,119 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!