Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <button onclick="startShuffle()">Shuffle</button>
    <div id="container"></div>


                #container {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-top: 20px;
    width: 500px;  /* 10個の要素を横並びに収めるための幅 */

#container > div {
    width: 40px;
    height: 40px;
    margin: 5px;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #f5a623;
    border: 1px solid #aaa;
    transition: transform 2s ease-in-out;  /* 2秒のゆっくりとしたアニメーション */



                const container = document.getElementById('container');
const numbers = Array.from({ length: 10 }, (_, i) => i + 1);
let isShuffling = false;  // シャッフル中かどうかを示すフラグ

function initialize() {
    for (const number of numbers) {
        const div = document.createElement('div');
        div.innerText = number;

function startShuffle() {
    if (isShuffling) return;  // シャッフル中の場合は何もしない

    isShuffling = true;  // シャッフルを開始
    const originalPositions = [...numbers];
    const shuffledNumbers = durstenfeldShuffle([...numbers]);
    animateShuffle(originalPositions, shuffledNumbers);

function updateUI(newNumbers) {
    const children = Array.from(container.children);
    for (let i = 0; i < children.length; i++) {
        children[i].innerText = newNumbers[i];

function durstenfeldShuffle(array) {
    for (let i = array.length - 1; i > 0; i--) {
        const randomIndex = Math.floor(Math.random() * (i + 1));
        [array[i], array[randomIndex]] = [array[randomIndex], array[i]];
    return array;

function animateShuffle(original, shuffled) {
    const children = Array.from(container.children);
    const originalRects = => child.getBoundingClientRect());

    const shuffledRects =, index) => {
        const newPosition = originalRects[original.indexOf(shuffled[index])];
        return newPosition;

    children.forEach((child, index) => {
        const dx = shuffledRects[index].left - originalRects[index].left; = `translateX(${dx}px)`;

    setTimeout(() => {
        children.forEach(child => {
  = ''; // 位置をリセット
        numbers.splice(0, numbers.length, ...shuffled);
        isShuffling = false;  // シャッフルが終了
    }, 2000);