JavaScript CSS/Javascript Scroll Replace Text css javascript scroll to bottom,css javascript scroll,css js

I'm trying to accomplish a couple things with JS/CSS that I can't figure out. Here's what I've got so far: http://codepen.io/melissall/pen/PPWPQE

  1. I want the headline to be centered in the image until the text scrolls up.

  2. I've got a CSS transition that changes the color of the text, but I don't want it to be timed, but based on the position of the headline. For an example of what I mean, check out how the logo changes color in this link: http://www.leaderbagco.com/

I've tried searching for examples, but I can't seem to find anything that helps. If anyone can point me in the right direction, that would be appreciated.

There's my code:

HTML

<div id="image"></div>
<div id="container" class="row">
  <div id="heading" class="large-12">
    <h2>Heading lorem ipsum sit dolor</h2>
  </div>
  <div id="content" class="large-12">
    <p> Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec nisi ante, pulvinar a lorem id, pellentesque facilisis diam. Cras placerat libero ut urna auctor faucibus. Morbi facilisis diam et massa facilisis, vel vulputate ex malesuada. Fusce varius, ex id vulputate accumsan, arcu orci scelerisque purus, et tempor orci leo et nisi. Aliquam aliquet massa vel nibh dictum viverra. Mauris dapibus quam ut magna congue porttitor. Aenean suscipit tortor a urna dapibus dignissim. In ornare risus et mauris pellentesque pharetra. Nunc et ultrices erat. Maecenas interdum dignissim turpis, in porta erat. Donec tortor urna, finibus ut quam ac, aliquam ullamcorper arcu. Vivamus id est quis ante volutpat laoreet. Proin fringilla pharetra est a sagittis. Fusce non magna mauris. Proin iaculis aliquet mi, a pellentesque dui porttitor ac. </p>
  </div>
</div>

CSS

h2{
  color: #ffffff;
  font-size: 4em;
  font-weight: 700;
  font-family: 'Roboto Condensed', sans-serif;
}
#image  {
  background: url(http://7-themes.com/data_images/out/78/7039061-beautiful-tropical-beach-wallpaper.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 500px;
}
#heading{
  position: relative;
  top: -250px;
  text-transform: uppercase;
  color: #fff;  
}
#heading h2{
  color: #fff;
  padding-top: 20px;
}

#heading h2.bgChange{
    color: #f00;

     -webkit-transition: color 1s;
       -moz-transition: color 1s;
        -ms-transition: color 1s;
         -o-transition: color 1s;
            transition: color 1s;
}
#content{
  padding-top: 100px;
}

JS

var windw = this;

$.fn.followTo = function ( pos ) {
    var $this = this,
        $window = $(windw);

    $window.scroll(function (e) {
        if ($window.scrollTop() > pos) {
            $this.css({
                position: 'absolute',
                top: pos
            });
        } else {
            $this.css({
                position: 'fixed',
                top: 0
            });
        }
    });
};

$('#heading').followTo(490);

$(window).scroll(function() {
  var addRemClass = $(window).scrollTop() > 470 ? 'addClass' : 'removeClass';
    $("#heading h2")[addRemClass]('bgChange');
});

EDIT #1:

I've got it sort of working with just CSS, but have run into other issues. The new link is here: http://codepen.io/melissall/pen/pjRZdx

New Issue #1: The headline doesn't stick above the copy anymore. I had to remove the JS that was there because it was interfering with the heading positions.

New Issue #2: If you scroll down far enough, the white text that was on the image reappears.

EDIT #2: Well I got it sorted (in CodePen at least) by adding some JS that detects when the page hits a certain point and changes the heading and copy to relative and absolute positions. And there's some other junk in there. The code is messy, and it still has flaws, but it functions in CodePen at the bare minimum of what I wanted to do. Here's the final code if anyone else is trying something similar: http://codepen.io/melissall/pen/pjRZdx

Answer:1

have you heard about : Parallax? https://github.com/wagerfield/parallax

That website you mentioned use the same concept.

I checked the link you provided I can see its 2 images: http://cdn.shopify.com/s/files/1/0556/3397/t/1/assets/leader-bag-co-bk.png?17257 http://cdn.shopify.com/s/files/1/0556/3397/t/1/assets/leader-bag-co-wh.png?17257

so basically he is not changing the logo color but the image instead.

see that website with top 50 parallax effects: http://www.creativebloq.com/web-design/parallax-scrolling-1131762

I hope my answer can help in something.

Answer:2

You can add some css styles and use jquery scroll to trigger the style if it meets the following condition.

body{}
h2{
  color: #ffffff;
  font-size: 5em;
  font-weight: 700;
  text-transform: uppercase;
  font-family: 'Roboto Condensed', sans-serif;
  height: 5em;
}
#image  {
  background: url(http://7-themes.com/data_images/out/78/7039061-beautiful-tropical-beach-wallpaper.jpg) no-repeat center center fixed; 
  -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
  height: 500px;
}


#content{
  padding-top: 100px;
}


.heading {
  position: absolute;
  height: 100%;
  border: 1px solid red;
  clip: rect(0, auto, auto, 0);
}

.copy.pink {
  position: fixed;
  top: 100px;
  color: pink;
}
/* Added this line to stick once its in the content */
.copy.pink.stick {
      position: static;
    display: block;
    width: 100%;
}

.copy.white {
    position: fixed;
    top: 100px;
    color: white;
}
/* Added this line to hide white copy once its in the content */
.copy.white.hidden {
  display:none;
}

JS

// Get distance of copy white from top
var whitedistance      = $('.copy.white').offset().top;
$( window ).scroll(function() {
  //Get distance of copy pink on top
  var wscrollTop     = $(window).scrollTop(),
    pinkOffset = $('.heading').offset().top,
    pinkdistance      = (pinkOffset - wscrollTop);
  console.log(pinkdistance + " == " + whitedistance)
// if distance of pink is less than or equal the height and the white is still visible add class hidden to hide it.
  if(pinkdistance <= whitedistance && !$('.copy.white').hasClass('hidden') ){
    console.log('hidden');
    $( ".copy.white" ).addClass( "hidden" );
    $( ".copy.pink" ).addClass( "stick" );
  }
  else if(pinkdistance > whitedistance && $('.copy.white').hasClass('hidden')){
// Display copy white again once the distance of copy pink is higher again than the white
    $( ".copy.white" ).removeClass( "hidden" );
    $( ".copy.pink" ).removeClass( "stick" );
  }
});

Hope this works. :)

Answer:3

I have a huge table that PHP gets from a db and displays. Every time php echos a few rows of the table, it flushes the output. So from the client's point of view, the table is basically growing bigger ...

I have a huge table that PHP gets from a db and displays. Every time php echos a few rows of the table, it flushes the output. So from the client's point of view, the table is basically growing bigger ...

  1. javascript flush event queue
  2. javascript flush event

I created a simple snake game after following some simple tutorials on YouTube. The problem is that the game does not have a pause function (e.g. when pressing P the game should pause/resume) and ...

I created a simple snake game after following some simple tutorials on YouTube. The problem is that the game does not have a pause function (e.g. when pressing P the game should pause/resume) and ...

Im trying to update a video's metadata using the Youtube API V3 in my AngularJS app. I am able to upload the video using insert. I had unlimited problems trying to set the video metadata at the same ...

Im trying to update a video's metadata using the Youtube API V3 in my AngularJS app. I am able to upload the video using insert. I had unlimited problems trying to set the video metadata at the same ...

I'm working on making a wysiwyg editor using slate.js I'm in a situation where I'm trying to find the first node with text. This picture below shows what I'm talking about: Slate.js find first text ...

I'm working on making a wysiwyg editor using slate.js I'm in a situation where I'm trying to find the first node with text. This picture below shows what I'm talking about: Slate.js find first text ...