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.

            
              section.text
  h1 This is an example of the crossfade() function for blending background images.
  
.hero

#control
  .slider-controls
    p
      label.title Change Cross-Fade
    p
      input(id="cross-fade-slider", type="range", min="0", max="100")
    p
      label Cross Fade =  
      span.percentage-output 50%
    
  .css-output
    | .hero { background-image: cross-fade (<span class="css-output-value">50</span>% url(https://cdn-images-1.medium.com/max/1600/1*o_vIFnBwhQIXh4qrzEYz7A.jpeg), url(https://www.desktopbackground.org/download/1600x900/2011/05/01/196572_audrey-hepburn-wallpapers-high-resolution-and-quality-download_2560x1920_h.jpg)); }

            
          
!
            
              body
  margin: 0
  

  
.hero
  height: 600px
  width: 100%
  // The cross fade % controls the opacity of the first image 
  // Note: to have a smooth transition with the slider, choose two images exactly the same size. Otherwise, you get a weird resizing thing.
  background: 
    image: cross-fade(50% url(https://cdn-images-1.medium.com/max/1600/1*o_vIFnBwhQIXh4qrzEYz7A.jpeg), url(https://www.desktopbackground.org/download/1600x900/2011/05/01/196572_audrey-hepburn-wallpapers-high-resolution-and-quality-download_2560x1920_h.jpg))
    position: center
    size: cover
    repeat: no-repeat
    
.text
  padding: 1rem
  
h1
  margin: 0  
  
// slider controls

#control
  display: flex
  justify-content: space-around
  max-width: 1200px
  margin: 2rem auto
  background: #f9f9f9
  padding: 1rem
  
.slider-controls
  flex: 0 1 30%
  text-align: center
  
.title
  font-size: 1.2rem
  
.css-output-value
  font-weight: 700
  
.css-output
  padding: 1rem 2rem
  line-height: 1.5
  border-left: 1px solid #ddd
  margin-left: 2rem
            
          
!
            
              $('#cross-fade-slider').on('input', function() {
  var $this = $(this);
  // the present slider value
  var sliderValue = $this.val();
  // output the present slider value
  $('.percentage-output').html(sliderValue + '%');
  // Webkit has a different way to write the function so you have to include that here, too
  $('.hero').css({
    'background-image' : 'cross-fade(' + sliderValue + '% url(https://cdn-images-1.medium.com/max/1600/1*o_vIFnBwhQIXh4qrzEYz7A.jpeg), url(https://www.desktopbackground.org/download/1600x900/2011/05/01/196572_audrey-hepburn-wallpapers-high-resolution-and-quality-download_2560x1920_h.jpg))',
    'background-image' : '-webkit-cross-fade(url(https://cdn-images-1.medium.com/max/1600/1*o_vIFnBwhQIXh4qrzEYz7A.jpeg), url(https://www.desktopbackground.org/download/1600x900/2011/05/01/196572_audrey-hepburn-wallpapers-high-resolution-and-quality-download_2560x1920_h.jpg), ' + sliderValue + '%)'
  });
  
  $('.css-output-value').text(sliderValue);
});
            
          
!
999px
Loading ..................

Console