<div id="sky"></div> <div id="sunsetSky"></div> <div id="nightSky"></div>
#sky { position: absolute; height: 60%; width: 100%; background: #004cf2; background: -moz-linear-gradient(top, #004cf2 0%, #00b7ea 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#004cf2), color-stop(100%,#00b7ea)); background: -webkit-linear-gradient(top, #004cf2 0%,#00b7ea 100%); background: -o-linear-gradient(top, #004cf2 0%,#00b7ea 100%); background: -ms-linear-gradient(top, #004cf2 0%,#00b7ea 100%); background: linear-gradient(top, #004cf2 0%,#00b7ea 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#004cf2', endColorstr='#00b7ea',GradientType=0 ); z-index: 1; } #sunsetSky { position: absolute; height: 60%; width: 100%; background: #1a4182; background: -moz-linear-gradient(top, #1a4182 0%, #ef6d56 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1a4182), color-stop(100%,#ef6d56)); background: -webkit-linear-gradient(top, #1a4182 0%,#ef6d56 100%); background: -o-linear-gradient(top, #1a4182 0%,#ef6d56 100%); background: -ms-linear-gradient(top, #1a4182 0%,#ef6d56 100%); background: linear-gradient(top, #1a4182 0%,#ef6d56 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1a4182', endColorstr='#ef6d56',GradientType=0 ); opacity: 0; z-index: 2; } #nightSky { position: absolute; height: 60%; width: 100%; background: #060a21; background: -moz-linear-gradient(top, #060a21 0%, #0a1638 80%, #181f59 100%); background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#060a21), color-stop(80%,#0a1638), color-stop(100%,#181f59)); background: -webkit-linear-gradient(top, #060a21 0%,#0a1638 80%,#181f59 100%); background: -o-linear-gradient(top, #060a21 0%,#0a1638 80%,#181f59 100%); background: -ms-linear-gradient(top, #060a21 0%,#0a1638 80%,#181f59 100%); background: linear-gradient(top, #060a21 0%,#0a1638 80%,#181f59 100%); filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#060a21', endColorstr='#181f59',GradientType=0 ); opacity: 0; z-index: 3; }
<div id="grass"></div> <div id="nightGrass"></div>
#grass { position: absolute; top: 60%; height: 40%; width: 100%; background: #42ab3f; z-index: 11; } #nightGrass { position: absolute; top: 60%; height: 40%; width: 100%; background: #000000; opacity: 0; z-index: 11; }
<div id="sun"> <div id="sunsetSun"></div> </div>
#sun { position: absolute; height: 100px; width: 100px; -webkit-border-radius: 50px; -moz-border-radius: 50px; border-radius: 50px; background: #eff866; box-shadow: 0 0 150px #eff866; z-index: 9; cursor: move; } #sunsetSun { height: 100%; width: 100%; border-radius: 50px; -webkit-border-radius: 50px; -moz-border-radius: 50px; background: #F9AD43; box-shadow: 0 0 150px #F9AD43; opacity: 0; }
.star { position: absolute; z-index: 5; background: #CEFFFA; height: 1px; width: 1px; opacity: 0; }
<script type="text/javascript"> $(function(){ // HTML var sun = document.getElementById('sun'); // jQuery var $sun = $(sun); // var $sunsetSun = $('#sunsetSun'); // var $sunsetSky = $('#sunsetSky'); // var $nightSky = $('#nightSky'); // var $grass = $('#grass'); // var $nightGrass = $('#nightGrass'); // Drag.init(sun); // "" 100 makeStars(100); // ( Drag.init() ) $sun.css({ 'top': 20, 'left': 300 }); // sun.onDrag = function(x, y){ // var sunTop = $sun.css('top'); // , var sunPosition = parseInt(sunTop) / (parseInt($sunsetSky.css('height')) / 100); // , var sunAbsolutePosition = parseInt(sunTop) / ($(window).height() / 100); // $sunsetSky.css('opacity', (Math.floor(sunPosition) / 100)); // $sunsetSun.css('opacity', (Math.floor(sunPosition) / 100)); // $nightGrass.css('opacity', (Math.floor(sunPosition) / 100)); // , 60% if (sunAbsolutePosition >= 40){ // , var start = $(window).height() / 100 * 40; // , , var end = $(window).height() / 100 * 65; // start end var pos = (parseInt(sunTop) - parseInt(start)) / ((parseInt(end) - parseInt(start)) / 100); // $nightSky.css('opacity', pos / 100); // $('.star').css('opacity', pos / 100); } // 60% , else { $('.star').css('opacity', 0); } } // start end function range(start, end){ if ((start >= 0) && (end >= 0)){ return Math.round(Math.abs(start) + (Math.random() * (Math.abs(end) - Math.abs(start)))); } else if ((start <= 0) && (end <= 0)){ return 0 - (Math.round(Math.abs(start) + (Math.random() * (Math.abs(end) - Math.abs(start))))); } else{ return Math.round(((start) + Math.random() * (end - start))); } } // count function makeStars(count){ for (var i=0; i<=count; i++){ // , var star = $(document.createElement('div')); // star star.addClass('star'); // DOM body star.appendTo('body'); // star.css({ // - 0 60% 'top': range(0, parseInt($(window).height()) / 100 * 60), // - 0 'left': range(0, $(window).width()) }); } } }); </script>
Source: https://habr.com/ru/post/135267/
All Articles