javascript - Simple CSS change when another div hits top of page -
javascript - Simple CSS change when another div hits top of page -
i have looked @ different posts , have found similar solutions, none of them allowed me need. have trying re-create effect found on url http://www.envisionboston.com/
when image gets top of page logo switches , div changes sizes... in past found way set when div gets top of page can alter or add together css element.
before top <div class="topbar">
when image gets top alter <div class="topbar fixed">
another issue have have headway themes nto allow me edit div in id , not class, not sure if changes things might.
i know should should able figure out have been on hours!
so, took time , found great reply on stackoverflow alter opacity while scrolling, , combined class removal/addition conditional:
jsfiddle demo
super helpful stackoverflow thread link jsfiddle alter opacity on scroll:
change div opacity on scroll
as far effect makes image "smaller," it's illusion. image's div overflow hidden, on scroll event, javascript adjusts top margin, "pushing" down. pushes image under < div > below it. when have bit more time, i'll see if can work answer. cheers
page desired effect: http://www.envisionboston.com/
block of code courtesy of stack link mentioned above:
function fader() { var b = $('.blue'), wh = $(window).height(), dt = $(document).scrolltop(), elview, opacity; h = $("#headerarea").height(); b.each(function () { elview = wh - ($(this).offset().top - dt); if (window.pageyoffset > (h + 50)) { $("#headerarea").removeclass("withheader").addclass("withoutheader"); } else { $("#headerarea").removeclass("withoutheader").addclass("withheader"); } if (elview > 0) { // top of div above bottom of window. opacity = 1 - 1 / (wh + $(this).height()) * elview; if (opacity > 0) // bottom of div below top of window. $(this).css('opacity', opacity); } }); } // event on scroll $(document).bind('scroll', fader);
original answer:
per link listed "site.js" file, here code making happen:
looking @ html file you'll find class beingness referenced ".main-image-wrapper" the code checks see if desired class exists
if (y.one('.main-image-wrapper'))
, says if current vertical position of page greater main image height + 80 pixels, add together class hides header
if ( (window.pageyoffset > (this.mainimageheight + 80)) ) { y.one('body').addclass('header-hidden');
the class removed else of above documented conditional. you'll notice header height changed in else conditional well.
else { y.one('body').removeclass('header-hidden'); this.headerheight = header.get('offsetheight'); }
there's great deal of styling , other subtleties happening, basically: check y position on page , if greater image height + number of desired pixels (80 in case) add together class hide header; otherwise, show it.
complete block of code below reference.
if (y.one('html.no-window-orientation')) { var scrollstates = function () { if (y.one('.main-image-wrapper')) { // 80 main content padding if ( (window.pageyoffset > (this.mainimageheight + 80)) ) { y.one('body').addclass('header-hidden'); this.headerheight = header.get('offsetheight'); if (y.one('.contact-inner-wrapper')) { y.all('.contact-inner-wrapper').setstyle('margintop', (this.headerheight + 5)); } } else { y.one('body').removeclass('header-hidden'); this.headerheight = header.get('offsetheight'); if (y.one('.contact-inner-wrapper')) { y.all('.contact-inner-wrapper').setstyle('margintop', (this.headerheight + 5)); } } y.one('.main-image-wrapper').setstyle('opacity', (1 - (window.pageyoffset / parseint(y.squarespace.template.gettweakvalue('bannerimageheight'), 10)))); y.one('.main-image-wrapper').setstyle('top', -(window.pageyoffset / 3)); } else { if ( (window.pageyoffset >= 80) ) { y.one('body').addclass('header-hidden'); this.headerheight = header.get('offsetheight'); if (y.one('.contact-inner-wrapper')) { y.all('.contact-inner-wrapper').setstyle('margintop', (this.headerheight + 5)); } } else { y.one('body').removeclass('header-hidden'); this.headerheight = header.get('offsetheight'); if (y.one('.contact-inner-wrapper')) { y.all('.contact-inner-wrapper').setstyle('margintop', (this.headerheight + 5)); } } } }; scrollstates(); y.one(window).on('scroll', function() { scrollstates(); }); }
javascript jquery html css
Comments
Post a Comment