javascript - Change element when other element is visible with jQuery -


i working on code involving persistent headers. possible when .floatingheader visible can make original hidden?

currently when scroll page, code is:

<h2 class="persist-header">some other area</h2> <h2 class="persist-header floatingheader" style="width: 545px; visibility: visible;">some other area</h2> 

but change to:

<h2 class="persist-header" style="visibility: hidden">some other area</h2> <h2 class="persist-header floatingheader" style="width: 545px; visibility: visible;">some other area</h2> 

here javascript:

function updatetableheaders() {     $(".persist-area").each(function() {         var el = $(this),             offset = el.offset(),             scrolltop = $(window).scrolltop(),             floatingheader = $(".floatingheader", this)          if ((scrolltop > offset.top) && (scrolltop < offset.top + el.height())) {             floatingheader.css({                 "visibility": "visible"             });         } else {             floatingheader.css({                 "visibility": "hidden"             });         };     }); }  // dom ready $(function() {     var clonedheaderrow;     $(".persist-area").each(function() {         clonedheaderrow = $(".persist-header", this);         clonedheaderrow             .before(clonedheaderrow.clone())             .css("width", clonedheaderrow.width())             .addclass("floatingheader");         });      $(window)         .scroll(updatetableheaders)         .trigger("scroll"); }); 

here demo: http://jsfiddle.net/j5z5tdjy/

try this.

       if ((scrolltop > offset.top) && (scrolltop < offset.top + el.height())) {            floatingheader.css({             "visibility": "visible"            });            floatingheader.prev().css({"visibility":"hidden"});        } else {            //$(".persist-header").css({"visibility":"visible"});            floatingheader.css({             "visibility": "hidden"            });            floatingheader.prev().css({"visibility":"visible"});        }; 

fiddle: http://jsfiddle.net/j5z5tdjy/4/


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -