JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
HTML Settings
Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.
<div class="center-outer">
<div class="center-inner">
<div class="bubbles">
<h1>Bubbling Header</h1>
</div>
</div>
</div>
/* Non essential CSS - Just for example centering */
html, body {
width: 100%;
height: 100%;
margin: 0;
}
.center-outer {
display: table;
width: 100%;
height: 100%;
}
.center-inner {
display: table-cell;
vertical-align: middle;
text-align: center;
}
/* Essential CSS - Makes the effect work */
body {
background-color: #3498db;
}
.bubbles {
display: inline-block;
font-family: arial;
position: relative;
}
.bubbles h1 {
position: relative;
margin: 1em 0 0;
font-family: 'Luckiest Guy', cursive;
color: #fff;
z-index: 2;
}
.individual-bubble {
position: absolute;
border-radius: 100%;
bottom: 10px;
background-color: #fff;
z-index: 1;
}
// Created for an Articles on:
// https://www.html5andbeyond.com/bubbling-text-effect-no-canvas-required/
jQuery(document).ready(function($){
// Define a blank array for the effect positions. This will be populated based on width of the title.
var bArray = [];
// Define a size array, this will be used to vary bubble sizes
var sArray = [4,6,8,10];
// Push the header width values to bArray
for (var i = 0; i < $('.bubbles').width(); i++) {
bArray.push(i);
}
// Function to select random array element
// Used within the setInterval a few times
function randomValue(arr) {
return arr[Math.floor(Math.random() * arr.length)];
}
// setInterval function used to create new bubble every 350 milliseconds
setInterval(function(){
// Get a random size, defined as variable so it can be used for both width and height
var size = randomValue(sArray);
// New bubble appeneded to div with it's size and left position being set inline
// Left value is set through getting a random value from bArray
$('.bubbles').append('<div class="individual-bubble" style="left: ' + randomValue(bArray) + 'px; width: ' + size + 'px; height:' + size + 'px;"></div>');
// Animate each bubble to the top (bottom 100%) and reduce opacity as it moves
// Callback function used to remove finsihed animations from the page
$('.individual-bubble').animate({
'bottom': '100%',
'opacity' : '-=0.7'
}, 3000, function(){
$(this).remove()
}
);
}, 350);
});
Also see: Tab Triggers