Randomly shuffle colors

Developer
Size
2,806 Kb
Views
20,240

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 Previews

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]); });
});
Randomly shuffle colors - Script Codes
Randomly shuffle colors - Script Codes
Home Page Home
Developer Cory
Username uniqname
Uploaded December 13, 2022
Rating 3
Size 2,806 Kb
Views 20,240
Do you need developer help for Randomly shuffle colors?

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!

Cory (uniqname) Script Codes
Create amazing video scripts with AI!

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!