Responsive honeycomb background with blinking eye bees
A Pen by thedoctor46super on CodePen.
Responsive honeycomb background with blinking eye bees
A Pen by thedoctor46super on CodePen.
| <html> | |
| <body> | |
| <menu> | |
| <input id="beeNumber" type="number" onchange="beeNumChange()" max="50" min="0" value="2" /> | |
| <span>Number of bees: </span> | |
| <div class="clearRight"></div> | |
| <input id="beePeriod" type="number" max="50" min="1" value="5" /> | |
| <span>Period (sec): </span> | |
| </menu> | |
| <div id="beeContainer"></div> | |
| </body> | |
| </html> |
| var beeSel = '.bee'; | |
| var rowOffset = 80, | |
| columnOffset = 48; | |
| var oddRowTopInit = 29, | |
| oddRowLeftInit = 29; | |
| var evenRowTopInit = 69, | |
| evenRowLeftInit = 5; | |
| var numOfRows, numOfColumns; | |
| $(function() { | |
| initialize(); | |
| }); | |
| $(window).resize(function() { | |
| defineGrid(); | |
| }); | |
| function initialize() { | |
| defineGrid(); | |
| createBees(); | |
| $.each($(beeSel), function(index, value) { | |
| $(value).blink(); | |
| }); | |
| } | |
| function defineGrid() { | |
| numOfRows = parseInt($(window).height() / (rowOffset / 2)); | |
| numOfColumns = parseInt($(window).width() / columnOffset); | |
| } | |
| function createBees() { | |
| $('#beeContainer').empty(); | |
| var beeNumber = $('#beeNumber').val(); | |
| if (beeNumber > 50) { | |
| beeNumber = 50; | |
| $('#beeNumber').val(50); | |
| } else if (beeNumber < 0) { | |
| beeNumber = 0; | |
| $('#beeNumber').val(0); | |
| } | |
| for (var i = 0; i < beeNumber; i++) { | |
| var newElem = $('<div>').addClass('bee').append( | |
| $('<div>').addClass('head').append( | |
| $('<div>').addClass('right-eye').append( | |
| $('<div>').addClass('no-border right-eye-pupil') | |
| ).append( | |
| $('<div>').addClass('no-border body eyelid-top') | |
| ).append( | |
| $('<div>').addClass('no-border body eyelid-bottom') | |
| ) | |
| ).append( | |
| $('<div>').addClass('left-eye').append( | |
| $('<div>').addClass('no-border left-eye-pupil') | |
| ).append( | |
| $('<div>').addClass('no-border body eyelid-top') | |
| ).append( | |
| $('<div>').addClass('no-border body eyelid-bottom') | |
| ) | |
| ) | |
| ); | |
| $('#beeContainer').append(newElem); | |
| } | |
| } | |
| function beeNumChange() { | |
| initialize(); | |
| } | |
| $.fn.blink = function() { | |
| this.css('top', oddRowTopInit + 'px'); | |
| this.css('left', oddRowLeftInit + 'px'); | |
| this.blinkAway(); | |
| } | |
| $.fn.blinkAway = function() { | |
| var jqElem = this; | |
| jqElem.fadeOut('slow', function() { | |
| var left, top; | |
| var beePeriod = $('#beePeriod').val() * 1000; | |
| if (beePeriod > 50000) { | |
| beePeriod = 50000; | |
| $('#beePeriod').val(50); | |
| } else if (beePeriod < 1000) { | |
| beePeriod = 1000; | |
| $('#beePeriod').val(1); | |
| } | |
| var randRow = Math.floor((Math.random() * numOfRows) + 1); | |
| var randCol = Math.floor((Math.random() * numOfColumns) - 1); | |
| randCol = randCol <= 0 ? 1 : randCol; | |
| var newColumnOffset = randCol * columnOffset; | |
| //console.log(randRow + ', ' + randCol); | |
| if (randRow % 2 == 0) { | |
| //even rows | |
| top = evenRowTopInit + (((randRow - 2) / 2) * rowOffset); | |
| left = evenRowLeftInit + newColumnOffset; | |
| } else { | |
| //odd rows | |
| top = oddRowTopInit + (((randRow - 1) / 2) * rowOffset); | |
| left = oddRowLeftInit + newColumnOffset; | |
| } | |
| jqElem.css('top', top + 'px'); | |
| jqElem.css('left', left + 'px'); | |
| jqElem.fadeIn('slow', function() { | |
| setTimeout(function() { | |
| jqElem.blinkAway(); | |
| }, beePeriod); | |
| }); | |
| }); | |
| } |
| <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> |
| html, | |
| body { | |
| margin: 0; | |
| padding: 0; | |
| overflow: hidden; | |
| } | |
| body { | |
| background-image: url('data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhYaHSUfGhsjHBYWICwgIyYnKSopGR8tMC0oMC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u { | |
| margin: 0; | |
| -webkit-border-radius: 4px; | |
| -moz-border-radius: 4px; | |
| border-radius: 4px; | |
| background-color: #333; | |
| border: 2px solid #FFF; | |
| box-shadow: 0 0 2px 2px #333; | |
| padding: 5px; | |
| display: inline-block; | |
| position: fixed; | |
| top: 5px; | |
| right: 5px; | |
| font-size: 10px; | |
| font-family: 'Segoe UI', Tahoma, Verdana; | |
| z-index: 999; | |
| opacity: 0.8; | |
| color: #FFF; | |
| text-align: right; | |
| } | |
| menu:hover { | |
| opacity: 1; | |
| } | |
| menu input { | |
| width: 35px; | |
| float: right; | |
| } | |
| menu span { | |
| -webkit-user-select: none; | |
| -moz-user-select: none; | |
| -ms-user-select: none; | |
| cursor: default; | |
| float: right; | |
| margin-top: 3px; | |
| } | |
| .bee * { | |
| position: absolute; | |
| box-sizing: content-box; | |
| -moz-box-sizing: content-box; | |
| } | |
| .clearRight { | |
| clear: right; | |
| } | |
| .bee { | |
| position: absolute; | |
| display: none; | |
| } | |
| .bee .head * { | |
| border: 1px solid #110b00; | |
| } | |
| .bee .head .no-border { | |
| border: none; | |
| } | |
| .bee .head .body { | |
| background: #fbd800; | |
| } | |
| .bee .head .eyelid { | |
| top: 55px; | |
| left: 63px; | |
| width: 10px; | |
| height: 10px; | |
| -webkit-border-radius: 50%; | |
| -moz-border-radius: 50%; | |
| border-radius: 50%; | |
| } | |
| .bee .head .right-eye { | |
| height: 18px; | |
| left: 18px; | |
| overflow: hidden; | |
| width: 18px; | |
| -moz-border-radius: 50%; | |
| -webkit-border-radius: 50%; | |
| border-radius: 50%; | |
| background: #ffffff; | |
| } | |
| .bee .head .right-eye .right-eye-pupil { | |
| top: 7px; | |
| left: 5px; | |
| width: 4px; | |
| height: 4px; | |
| -moz-border-radius: 50%; | |
| -webkit-border-radius: 50%; | |
| border-radius: 50%; | |
| background: #110b00; | |
| } | |
| .bee .head .right-eye .eyelid-top { | |
| top: -18px; | |
| left: 0px; | |
| width: 30px; | |
| height: 17px; | |
| border-bottom: 1px solid #110b00; | |
| border-radius: 50% 50% 0 0; | |
| -webkit-animation-name: beerighteyelidtop; | |
| -webkit-animation-duration: 8s; | |
| -webkit-animation-timing-function: linear; | |
| -webkit-animation-delay: 2.5s; | |
| -webkit-animation-iteration-count: infinite; | |
| -webkit-animation-play-state: running; | |
| animation-name: beerighteyelidtop; | |
| animation-duration: 8s; | |
| animation-timing-function: linear; | |
| animation-delay: 2.5s; | |
| animation-iteration-count: infinite; | |
| animation-play-state: running; | |
| } | |
| .bee .head .right-eye .eyelid-bottom { | |
| bottom: -11px; | |
| left: 0px; | |
| width: 30px; | |
| height: 10px; | |
| border-top: 1px solid #110b00; | |
| border-radius: 0 0 50% 50%; | |
| -webkit-animation-name: beerighteyelidbottom; | |
| -webkit-animation-duration: 8s; | |
| -webkit-animation-timing-function: linear; | |
| -webkit-animation-delay: 2.5s; | |
| -webkit-animation-iteration-count: infinite; | |
| -webkit-animation-play-state: running; | |
| animation-name: beerighteyelidbottom; | |
| animation-duration: 8s; | |
| animation-timing-function: linear; | |
| animation-delay: 2.5s; | |
| animation-iteration-count: infinite; | |
| animation-play-state: running; | |
| } | |
| @-webkit-keyframes beerighteyelidtop { | |
| 0% { | |
| top: -18px; | |
| } | |
| 2% { | |
| top: 0px; | |
| } | |
| 4% { | |
| top: -18px; | |
| } | |
| 100% { | |
| top: -18px; | |
| } | |
| } | |
| @keyframes beerighteyelidtop { | |
| 0% { | |
| top: -18px; | |
| } | |
| 2% { | |
| top: 0px; | |
| } | |
| 4% { | |
| top: -18px; | |
| } | |
| 100% { | |
| top: -18px; | |
| } | |
| } | |
| @-webkit-keyframes beerighteyelidbottom { | |
| 0% { | |
| bottom: -11px; | |
| } | |
| 2% { | |
| bottom: 0px; | |
| } | |
| 4% { | |
| bottom: -11px; | |
| } | |
| 100% { | |
| bottom: -11px; | |
| } | |
| } | |
| @keyframes beerighteyelidbottom { | |
| 0% { | |
| bottom: -11px; | |
| } | |
| 2% { | |
| bottom: 0px; | |
| } | |
| 4% { | |
| bottom: -11px; | |
| } | |
| 100% { | |
| bottom: -11px; | |
| } | |
| } | |
| .bee .head .left-eye { | |
| height: 20px; | |
| overflow: hidden; | |
| width: 20px; | |
| -moz-border-radius: 50%; | |
| -webkit-border-radius: 50%; | |
| border-radius: 50%; | |
| background: #ffffff; | |
| } | |
| .bee .head .left-eye .left-eye-pupil { | |
| height: 4px; | |
| left: 5px; | |
| top: 8px; | |
| width: 4px; | |
| -moz-border-radius: 50%; | |
| -webkit-border-radius: 50%; | |
| border-radius: 50%; | |
| background: #110b00; | |
| } | |
| .bee .head .left-eye .eyelid-top { | |
| top: -21px; | |
| left: 0px; | |
| width: 30px; | |
| height: 20px; | |
| border-bottom: 1px solid #110b00; | |
| border-radius: 50% 50% 0 0; | |
| -webkit-animation-name: beelefteyelidtop; | |
| -webkit-animation-duration: 8s; | |
| -webkit-animation-timing-function: linear; | |
| -webkit-animation-delay: 2.5s; | |
| -webkit-animation-iteration-count: infinite; | |
| -webkit-animation-play-state: running; | |
| animation-name: beelefteyelidtop; | |
| animation-duration: 8s; | |
| animation-timing-function: linear; | |
| animation-delay: 2.5s; | |
| animation-iteration-count: infinite; | |
| animation-play-state: running; | |
| } | |
| .bee .head .left-eye .eyelid-bottom { | |
| bottom: -11px; | |
| left: 0px; | |
| width: 30px; | |
| height: 10px; | |
| border-top: 1px solid #110b00; | |
| border-radius: 0 0 50% 50%; | |
| -webkit-animation-name: beelefteyelidbottom; | |
| -webkit-animation-duration: 8s; | |
| -webkit-animation-timing-function: linear; | |
| -webkit-animation-delay: 2.5s; | |
| -webkit-animation-iteration-count: infinite; | |
| -webkit-animation-play-state: running; | |
| animation-name: beelefteyelidbottom; | |
| animation-duration: 8s; | |
| animation-timing-function: linear; | |
| animation-delay: 2.5s; | |
| animation-iteration-count: infinite; | |
| animation-play-state: running; | |
| } | |
| @-webkit-keyframes beelefteyelidtop { | |
| 0% { | |
| top: -21px; | |
| } | |
| 2% { | |
| top: 0px; | |
| } | |
| 4% { | |
| top: -21px; | |
| } | |
| 100% { | |
| top: -21px; | |
| } | |
| } | |
| @keyframes beelefteyelidtop { | |
| 0% { | |
| top: -21px; | |
| } | |
| 2% { | |
| top: 0px; | |
| } | |
| 4% { | |
| top: -21px; | |
| } | |
| 100% { | |
| top: -21px; | |
| } | |
| } | |
| @-webkit-keyframes beelefteyelidbottom { | |
| 0% { | |
| bottom: -11px; | |
| } | |
| 2% { | |
| bottom: 0px; | |
| } | |
| 4% { | |
| bottom: -11px; | |
| } | |
| 100% { | |
| bottom: -11px; | |
| } | |
| } | |
| @keyframes beelefteyelidbottom { | |
| 0% { | |
| bottom: -11px; | |
| } | |
| 2% { | |
| bottom: 0px; | |
| } | |
| 4% { | |
| bottom: -11px; | |
| } | |
| 100% { | |
| bottom: -11px; | |
| } | |
| } |