javascript - Positioning fixed element within an iframe depending on parent window scroll -
goal: i'm trying accomplish have sticky element in iframe positioned @ bottom of browser window - until hits bottom of iframe window, then, when scrolling further down on parent page element stays put, , if 1 scrolling again element positions @ bottom of browser window again.
without iframe simple solution (and showcase of want achieve) this: https://jsfiddle.net/30a1sxk9/2/
my page containing iframe looks this: https://jsfiddle.net/q9m1h2j5/1/
-> since scrolling happening outside iframe fixed position @ bottom.
i'm looking robust , performant solution position element (with proper boundaries) in iframe within iframe. main problem have no access surrounding page - except via javascript within iframe (cross origin should not make problems since container , iframe have same domain)
can't guarantee outside of iframe, have take account determining position of element. can't change general setup of page.
my approach this, inside iframe:
let $footer = $('.sticky-footer'); window.parent.onscroll = function() { let footerpos = this.scrolly + this.innerheight - 60; console.debug('onscroll: ', footerpos); $footer.css({ position: 'absolute', top: footerpos + 'px' }) };
where put onscroll listener on window.parent , calculating , setting absolute position of element each event call.
but i'm having trouble figuring out how calculate exact absolute position sticky-footer supposed , boundaries allowed move. i'd have determine exact y top position of iframe , bottom position - somehow reliably possible?
also i'm not sure if setting absolute position approach - since after first prototyping noticed jittering when scrolling fast - maybe css transformations better? or there different way achieve this?
any help, solutions , hints appreciated!
Comments
Post a Comment