How do you get this result, using Jquery Scroll Event & offset/position, css or javascript? -


how result in css, javascript or jquery, or combination of all:

enter image description here

i asked , posted similar question before, no 1 answered it. said:

"maybe can use javascript (or bether jquery) this.  if use jquery, can use scroll event. if scrolling,  check if hits other div. https://api.jquery.com/scroll/  checking positions of divs possible offset/position.      http://api.jquery.com/offset/ https://api.jquery.com/position/  if want change background, give div background color   pink. if hits can add additional background-image    has specific background-position  (http://www.w3schools.com/cssref/pr_background-position.asp xpos ypos).    don't have tried yet, guess possible way." 

so question is, how go doing result or regardless of way?

i came after couple of hours trying make work. pretty fun doing it, i'm sharing it.

$(document).ready(function() { var initscrolltop = $(window).scrolltop(); $('.div1').css('top', (initscrolltop+100)+"px");  $(window).scroll(function () {     var top = parseint($('.div1').css('top').split("px")[0]);      // give fixed top .div1     var scrolltop = $(this).scrolltop() + 100;     $('.div1').css('top', scrolltop+"px");      // getting values      // div1     var div2top = parseint($('.div2').css('top').split('px')[0]);     var div2height = parseint($('.div2').css('height').split('px')[0]);     var div2bottom = parseint($('.div2').css('bottom').split('px')[0]);      // div2      var div1width = parseint($('.div1').css('width').split('px')[0]);     var div1height = parseint($('.div1').css('height').split('px')[0]);     var div1top = parseint($('.div1').css('top').split('px')[0]);     var div1bottom = parseint($('.div1').css('bottom').split('px')[0]);     var div1left = parseint($('.div1').css('left').split('px')[0]);      // going through green box     if(scrolltop + div1height > div2top) {           // outside of green box (.div2)         if(scrolltop + div1height > div2height + div2top) {              var div3height = div2top + div2height - scrolltop;             $('.div3').css('top', scrolltop+ "px")                      // .css('bottom', div2bottom + "px")                       .css('width', div1width + "px")                       .css('height', div3height + "px")                       .css('visibility','visible');                       console.log("i'm out");         }           // inside of green box (.div2)         else {              var div3height = (div1top > div2top) ? div1height : scrolltop + div1height - div2top;             var div3top = (div1top > div2top) ? div1top : div2top;             $('.div3').css({                 'top' : div3top + "px",                 'left': div1left + "px",                 'width': div1width + "px",                 'height': div3height + "px",                 'visibility':'visible'                 });          }      } else {          $('.div3').css('visibility','hidden');     }       // absolutely out of green box (from bottom going down)     if(scrolltop > div2top + div2height) {       $('.div3').css('visibility','hidden');        }   });  }); 

here's there fiddle can test http://jsfiddle.net/5076h670/2/

so create 3 divs, 2 of them visible , 'collide' between each other, other 1 starts hidden , shows when position of div1 in range of div2. div3 (the third div) shown on div1 (see z-index). when it's absolutely out of box div3 hidden.

i don't know else explain code, don't know if (and don't think, took me while make work) it's understandable does. if have ask i'll reading ;)

hope helps


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -