Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

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

Packages

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.

Behavior

Save Automatically?

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.

HTML

              
                <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"
        integrity="sha512-894YE6QWD5I59HgZOGReFYm4dnWc1Qt5NtvYSaNcOP+u1T9qYdvdihz0PPSiiqn/+/3e7Jo4EaG7TubfWGUrMQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/js/bootstrap.min.js"
        integrity="sha512-EKWWs1ZcA2ZY9lbLISPz8aGR2+L7JVYqBAYTq5AXgBkSjRSuQEGqWx8R1zAX16KdXPaCjOCaKE8MCpU0wcHlHA=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/5.0.1/css/bootstrap.min.css"
        integrity="sha512-Ez0cGzNzHR1tYAv56860NLspgUGuQw16GiOOp/I2LuTmpSK9xDXlgJz3XN4cnpXWDmkNBKXR/VDMTCnAaEooxA=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />

    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
        integrity="sha512-iBBXm8fW90+nuLcSKlbmrPcLa0OT92xO1BIsZ+ywDWZCvqsWgccV3gFoRBv0z+8dLJgyAHIhR35VZc2oM/gI1w=="
        crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="container">
        <div class="card text-center mt-5">
            <div class="card-header">
                <div class="d-flex align-items-center justify-content-between">
                    <span>
                        <button class="btn btn-outline-dark float-start" onclick="refreshGallery()">Refresh</button>
                        <button class="btn btn-outline-danger float-start mx-2" onclick="loadImagesToGallery(4)">Load Random
                            Images</button>
                    </span>
                    <span>Create image gallery</span> 
                    <span class="float-end">Total images: 
                        <span class="loaded-images-count-js">0</span>
                    </span>
                </div>

                <div class="clear-both"></div>

                <div class="input-group mb-3 mt-3">
                    <span class="input-group-text" id="basic-addon1"> <i class="fa fa-search"></i> </span>
                    <input id="search-image" type="text" class="form-control" placeholder="Search image here.."
                        aria-describedby="basic-addon1" value="">
                </div>
            </div>
            <div class="card-body h-px-700 position-relative card-area-js overflow-scroll">

                <div class="image-gallery-js d-flex flex-wrap justify-content-around">

                </div>


            </div>
        </div>
    </div>
              
            
!

CSS

              
                .h-px-700 {
            height: 700px;
        }
              
            
!

JS

              
                var api_key = "15819227-ef2d84d1681b9442aaa9755b8";
        var query = "nature";
        var images = [];
        var loaded_count = 0;
        var page = 1;

        var image_card_html = (src) => {
            return `<div class="card img-card-js mt-2" style="width: 18rem;">
                                        <img src="${src}" class="card-img-top" alt="...">
                                        <div class="card-body">
                                            <h5 class="card-title">Card title</h5>
                                            <p class="card-text">Some quick example text to build on the card title and make up the bulk
                                                of the card's content.</p>
                                            <a href="#" class="btn btn-primary">Go somewhere</a>
                                        </div>
                                    </div>`;
        }


        async function getImages(per_page) {
            console.log({query});
            const response = await fetch(
                `https://pixabay.com/api/?key=${api_key}&q=${query
                }&image_type=""&per_page=${per_page}&page=${page}`
            );
            const data = await response.json();
            return data.hits;
        }

        function loadImagesToGallery(per_page) {

            getImages(per_page).then(imgObj => {
                imgObj.forEach((value, index) => {
                    console.log({value});
                    var gallery = $('.image-gallery-js');

                    gallery.append(image_card_html(value.userImageURL));

                    updateImageCounts(++loaded_count);
                })
            })

        }

        function updateImageCounts(num) {
            var counts = $('.loaded-images-count-js');
            counts.text(num);
        }

        function refreshGallery() {
            loaded_count = 0;
            page = 1;
            var gallery = $('.image-gallery-js');
            gallery.find('.img-card-js').remove();
            updateImageCounts(0);
            $('#search-image').val('');
        }

        $('#search-image').on('keypress', function(e) {
            console.log(e.which);
            if (e.which == 13 && !e.shiftKey) {
                e.preventDefault();
                if ( $(this).val().trim() ) {
                    query = this.value;
                    refreshGallery();
                    $(this).val(query);
                }
                
                loadImagesToGallery(12);
            }
        })
              
            
!
999px

Console