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

              
                  <div id="wrapper">
    <main>
      <h1>Animated ✨ Sparkles Demo</h1>
      <h2>This is a jQuery demo for a sparkling stars effect</h2>
      <p>
        Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod <span class="sparkling">tempor incididunt</span> ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure <span class="sparkling">dolor in reprehenderit</span> in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
      </p>
    </main>
    <footer>
      <div><a href="https://renerehme.dev/blog/animated-sparkles-in-jquery" target="_blank"> read the article</a></div>
      <div>© 2020 Rene Rehme. All Rights Reserved.</div>
    </footer>
  </div>

              
            
!

CSS

              
                /* sparkling stars */
@-webkit-keyframes comeInOut {
    0% { transform: scale(0); }
    50% { transform: scale(1); }
    100% { transform: scale(0); }
}
@-moz-keyframes comeInOut {
    0% { transform: scale(0); }
    50% { transform: scale(1); }
    100% { transform: scale(0); }
}
@-o-keyframes comeInOut {
    0% { transform: scale(0); }
    50% { transform: scale(1); }
    100% { transform: scale(0); }
}
@keyframes comeInOut {
    0% { transform: scale(0); }
    50% { transform: scale(1); }
    100% { transform: scale(0); }
}

@-webkit-keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(180deg); }
}
@-moz-keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(180deg); }
}
@-o-keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(180deg); }
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(180deg); }
}

.sparkling {
    position: relative;
    display: inline-block;
    z-index: 0;
    font-weight: bold;
    color: #FFC700;
}

.sparkling > span {
    z-index: -1;
    position: absolute;
    display: block;
    animation: comeInOut 700ms forwards;
}

.sparkling > span > svg {
    display: block;
    animation: spin 1000ms linear;
}

/* basic styling - not necessary */
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro);

body {
    background: #222;
    color: white;
    font-family: 'Source Sans Pro', sans-serif;
    font-size: 17px;
    font-weight: 400;
    margin: 0;
}

#wrapper {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 15px;
}

main h1 {
    display: inline-block;
    font-size: 28px;
    font-weight: 600;
    text-transform: uppercase;
    padding-bottom: 3px;
    margin: 17px 0 0 0;
    border-bottom: 3px solid #FFC700;
}

main h2 {
    display: block;
    font-size: 22px;
    font-weight: 200;
    padding-bottom: 3px;
    margin: 10px 0 30px 0;
}

main p {
    display: block;
    line-height:24px;
}

footer {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    font-size: 16px;
    color: #858585;
    background: #353535;
    margin-top: 30px;
    padding: 20px;
}

footer div {
    padding: 10px;
}

footer a {
    color: #FFC700;
    border-bottom: 2px dashed rgb(255 199 0 / 24%);
    padding-bottom: 3px;
    text-decoration: none;
}

footer a:hover {
    color: #FFC700;
    border-bottom: 2px dashed rgb(255 199 0);
    padding-bottom: 3px;
    text-decoration: none;
}
              
            
!

JS

              
                function initSparkling() {
    // settings
    const color = "#FFC700";
    const svgPath = 'M26.5 25.5C19.0043 33.3697 0 34 0 34C0 34 19.1013 35.3684 26.5 43.5C33.234 50.901 34 68 34 68C34 68 36.9884 50.7065 44.5 43.5C51.6431 36.647 68 34 68 34C68 34 51.6947 32.0939 44.5 25.5C36.5605 18.2235 34 0 34 0C34 0 33.6591 17.9837 26.5 25.5Z';

    // sparkling effect
    let sparkling = function() {
        $('.sparkling').each(function() {
            let sparklingElement = $(this);
            let stars = sparklingElement.find('.star');

            // remove the first star when more than 6 stars existing
            if(stars.length > 5) {
                stars.each(function(index) {
                    if(index === 0) {
                        $(this).remove();
                    }
                });
            }
            // add a new star
            sparklingElement.append(addStar());
        });

        let rand = Math.round(Math.random() * 700) + 100;
        setTimeout(sparkling, rand);
    }
			
    // star
    let addStar = function() {
        let size = Math.floor(Math.random() * 20) + 10;
        let top = Math.floor(Math.random() * 100) - 50;
        let left = Math.floor(Math.random() * 100);

        return '<span class="star" style="top:' + top + '%; left:' + left + '%;">'
            + '<svg width="' + size + '" height="' + size + '" viewBox="0 0 68 68" fill="none">'
            + '<path d="' + svgPath + '" fill="' + color + '" /></svg></span>';
    }

    // execute
    sparkling();
}

$(function() {
    // init sparkling stars
    initSparkling();
});
              
            
!
999px

Console