cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="wrapper" 
     data-color-left-start="#FFFE4D" 
     data-color-left-end="#3FD18B" 
     data-color-right-start="#FF7B4D" 
     data-color-right-end="#9B46CD"
     data-color-top="#fffec4"
     data-color-bottom="#15081d">
  <div class="content"></div>
</div>
            
          
!
            
              html, body {
  position: relative;
  height: 100%;
}

#wrapper {
	width: 100%;
	height: 100%;
	overflow-y: auto;
}

#wrapper .content {
	position: relative;
	height: calc(100% * 4);
}
            
          
!
            
              window.requestAnimationFrame = window.requestAnimationFrame
|| window.mozRequestAnimationFrame
|| window.webkitRequestAnimationFrame
|| window.msRequestAnimationFrame
|| function(f){return setTimeout(f, 1000/60)};

HTMLElement.prototype.scrollColorize = (() => {

	class Color {
		
    constructor(rgbOrHex) {
      var isHexDef = typeof rgbOrHex === 'string';
      this.rgb = (isHexDef)? Color.hexToRgb(rgbOrHex): rgbOrHex;
      this.hex = (!isHexDef)? Color.rgbToHex(rgbOrHex): rgbOrHex;
    }
    
    static hexToRgb(hex) {
      var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex).splice(1, 4);
      return rgb.map(c => parseInt(c, 16));
    }
    
    static rgbToHex(rgb) {
      return `#${rgb.map(c => {
        var hex = c.toString(16),
          trailing = hex.length === 1? '0': '';
        return trailing + hex;
      }).join('')}`;
	  }
    
    static transformColor(from, to, percentage) {
      return new Color(from.rgb.map((color, index) => {
        return Math.round(color - ((color - to.rgb[index]) * percentage / 100));
      }));
    }
	}

	function getScrollPercentage(element) {
		return Math.round(element.scrollTop / (element.scrollHeight - element.clientHeight) * 100);
	}
  
  function drawBackground(element) {
    var percentage = getScrollPercentage(element),
        opacity = percentage / 100,
        left = Color.transformColor(element.leftStart, element.leftEnd, percentage),
        right = Color.transformColor(element.rightStart, element.rightEnd, percentage);
    element.style.backgroundImage = `
      linear-gradient(to bottom, 
        rgba(${element.topColor.rgb.join(',')}, ${1 - opacity}), 
        rgba(${element.bottomColor.rgb.join(',')}, ${opacity})
      ), 
      linear-gradient(to right, ${left.hex}, ${right.hex})
    `;
  }

	return function() {
		this.leftStart    = new Color(this.getAttribute('data-color-left-start'));
		this.leftEnd      = new Color(this.getAttribute('data-color-left-end'));
		this.rightStart   = new Color(this.getAttribute('data-color-right-start'));
		this.rightEnd     = new Color(this.getAttribute('data-color-right-end'));
    this.topColor     = new Color(this.getAttribute('data-color-top'));
    this.bottomColor  = new Color(this.getAttribute('data-color-bottom'));
    
    drawBackground(this);

		this.addEventListener('scroll', () =>{
			window.requestAnimationFrame(() => {
        drawBackground(this);
      });
		});
	}
})();

document.addEventListener('DOMContentLoaded', function(){
	this.querySelector('#wrapper').scrollColorize();
});

            
          
!
999px
Loading ..................

Console