LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code
Using Simple JS/jQuery and classes to get a cool transition effect on scroll.

(On phone view in debug mode)

01

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.

02

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.

03

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.

04

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin non varius nulla. Pellentesque sit amet sodales eros. Nam quis nibh vitae risus feugiat pulvinar vel eu est. Nam ex massa, rhoncus mattis est ac, iaculis vulputate nisl. Donec maximus nisi eu ipsum semper, eu euismod mi sodales. Nunc id felis sit amet sem faucibus placerat. Sed consectetur lectus metus, et ullamcorper nisi fermentum sit amet. Sed in volutpat magna, nec accumsan orci. Aenean turpis lectus, tincidunt nec diam et, condimentum scelerisque nisi. Aenean elementum neque eros, et interdum enim faucibus et. Cras eleifend interdum felis, non dignissim purus vulputate in. Suspendisse vel nunc dolor. Curabitur venenatis nisi non odio auctor, et malesuada odio tincidunt.

CSS
@import url(https://fonts.googleapis.com/css?family=Roboto:300,700);

#wrapper{
  width: 100%;
  height: 100%;
  font-family: 'Roboto', sans-serif;
  /*transition for the background color*/
  -webkit-transition: background-color 500ms;
   -moz-transition: background-color 700ms;
   -o-transition: background-color 700ms;
   transition: background-color 700ms;
}

/*color classes to be applied to "#wrapper" by the js*/
.colorOne{
  background-color: #BF3F3F;
}
.colorTwo{
  background-color: #59A57F;
}
.colorThree{
  background-color: black;
}
.colorFour{
  background-color: #7FBF3F;
}

/*layout styles not really relevant to this demo*/

header{
  width: 100%;
  color: white;
  background-color: #191919;
  text-align: center;
  padding: 1em 0 1em 0;
  margin-bottom: 100px;
}
h2{
  font-size: .7em;
  padding-top: .5em;
}

.item{
  width: 100%; 
  max-width: 600px;
  margin: 0 auto;
  height: 650px;
  padding: 0px 0 10px 0;
}

h1{
  color: white;
  display: inline-block;
  width: 32%;
  vertical-align: top;
  font-size: 10em;
  font-weight: 700;
}
p{
  width: 64%;
  display: inline-block;
  color: white;
  line-height: 170%;
  font-size: .9em;
  font-weight: 300;
}

@media screen and (max-width: 550px) {
  h1{
    display: block;
    width: 90%;
    margin-left: 3%;
  }
  p{
    display: block;
    width: 90%;
    margin-left: 3%;
  }
  header{
    margin-bottom: 30px;
  }
  
}

JS
/*
this function will add different background color classes to "#wrapper" when the window is scrolled to a certain height. It will also remove the next color class so it reverts to the appropriate color when the user scrolls back up. Could be simplified, but this is easy to understand and alter.
*/

$(window).scroll(function() {
  if ($(this).scrollTop() <= 450) {
    $('#wrapper').addClass('colorOne')
      .removeClass('colorTwo');
  } else if ($(this).scrollTop() <= 1000) {
    $('#wrapper').addClass('colorTwo')
      .removeClass('colorThree');
  } else if ($(this).scrollTop() <= 1500) {
    $('#wrapper').addClass('colorThree')
      .removeClass('colorFour');
  } else if ($(this).scrollTop() <= 1850) {
    $('#wrapper').addClass('colorFour')
      .removeClass('colorFive');
  } else {
    $('#wrapper').addClass('colorOne')
  }
});

Description

Pretty easy to digest and cool background color transition effect on user scroll using javascript/jQuery and css. Could also be used for background images. On phone view in debug mode.
Term
Mon, 11/27/2017 - 21:31

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv