I'd like to use the jQuery code below in a React component as a banner's background in a website. Importing the css worked, but neither importing nor placing the JS in render(){} worked. How can this be done?
codepen: https://codepen.io/dooblr/pen/BXwWyJ
html:
<div class="sea">
<div class="bubblesContainer"></div>
</div>
css:
body {
margin: 0;
padding: 0;
overflow-x: hidden;
box-sizing: border-box;
}
.sea {
height: 19000px;
background-image: linear-gradient(to bottom, #1cb5e0, #000046);
min-height: 100%;
position: relative;
}
.bubbles {
background: radial-gradient(transparent, #eef2f3);
box-shadow: 0 0 4px #eef2f3, inset 0 0 8px #eef2f3;
border-radius: 50%;
position: absolute;
z-index: 2;
}
@keyframes bubblingUp {
100% { transform: translatey(-1000px); }
}
js:
var scrollPosition = 0;
var numberBubbles = 200;
while (numberBubbles > 0){
$(".bubblesContainer").append('<div class="bubbles"></div>');
numberBubbles--;
}
$( ".bubbles").each(function( index ) {
var x = (Math.random() * ($('body').width()));
var y = (Math.random() * ($('body').height()));
var minSpeed = (Math.random() * 20);
var speed = (minSpeed + Math.random() * 20 + 's');
var widthHeight = Math.floor(Math.random() * 40)
$(this).css({
'left': x + 'px',
'top': y + 'px',
'width': widthHeight +"px",
'height': widthHeight +"px",
'animation': 'bubblingUp ' + speed + ' infinite ease-out'
});
var delay = Math.floor(Math.random() * 100);
$(this).hide().delay(delay).fadeIn();
});