<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Priyanshu Kumar on Medium]]></title>
        <description><![CDATA[Stories by Priyanshu Kumar on Medium]]></description>
        <link>https://medium.com/@priyanshu.kumar_4552?source=rss-fcd1891115ff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FMY-fLvdoyiUv7Vp</url>
            <title>Stories by Priyanshu Kumar on Medium</title>
            <link>https://medium.com/@priyanshu.kumar_4552?source=rss-fcd1891115ff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:34:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@priyanshu.kumar_4552/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to avoid double scroll bars when embedding on the Web]]></title>
            <link>https://medium.com/thoughtspotdev/how-to-avoid-double-scroll-bar-while-embedding-470891a8d807?source=rss-fcd1891115ff------2</link>
            <guid isPermaLink="false">https://medium.com/p/470891a8d807</guid>
            <dc:creator><![CDATA[Priyanshu Kumar]]></dc:creator>
            <pubDate>Sun, 23 Mar 2025 16:09:13 GMT</pubDate>
            <atom:updated>2025-03-25T05:27:25.914Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Tp6szsVhwIEyOh9uUIkBw.png" /></figure><h3>The Problem: A Tale of Two Scrollbars</h3><p>When you embed any external content — into your web page using an iframe, you’ll often run into the infamous “iframe sizing conundrum”. <br>Your goal is to have the embedded application occupy the full height within the host application. In other words, you want the embedded content to fit the space perfectly, without any unsightly scrollbars or blank spaces.</p><p>But here’s the rub: if things aren’t set up just right, you might end up with <strong>double scrollbars</strong>. Imagine trying to use two remote controls for one TV — it’s confusing, frustrating, and just a bad user experience!</p><h3>What’s Causing the Double Scrollbars?</h3><p>Double scrollbars occur when both the host application <strong>and</strong> the embedded content are scrollable:</p><ul><li><strong>Scrollable Host Application:</strong> If the height of your host page exceeds the viewport (thanks to extra content like headers, footers, or just long pages), your entire application becomes scrollable.</li><li><strong>Scrollable Embedded Content:</strong> Meanwhile, if the embedded content is larger than the <strong>iframeHeight</strong>, it gets its own scrollbar.</li></ul><p>Now users have to deal with two sets of scrolling — one for the page and one for the iframe.</p><h3>Breaking Down the Technical Metrics</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_MGlmc9CQ4HIE41vTCUmBA.png" /></figure><p>To understand and solve this, let’s look at a few key metrics:</p><p><strong>offsetTopClient:</strong> This is the number of pixels between the top edge of the host app and the top edge of your iframe</p><pre>const offsetTopClient = this.iFrame.offsetTop;</pre><p><strong>scrollTopClient:</strong> This indicates how far the host app is scrolled vertically</p><pre>const offsetTopClient = this.iFrame.offsetTop;</pre><p><strong>viewPortHeight (Host App):</strong> This represents the total height of the viewport.</p><pre>const viewPortHeight = window.innerHeight;</pre><p><strong>iframeHeight:</strong> The dynamic height you need to assign to the ThoughtSpot iframe so that it fits snugly within the available space.</p><h3>Possible Solutions</h3><ol><li><strong><em>Sync host-app scroll-bar with iframe scroll-bar :</em></strong> Ensure seamless scrolling synchronisation between the host app and iframe by matching scroll positions dynamically as the user interacts with either element.</li><li><strong><em>Adaptive iframe height:</em></strong> The core idea is to ensure the iframe height dynamically matches the available space while accounting for your layout’s structure</li></ol><p>We will discuss both of the above solution in context of <a href="https://thoughtspot.com/"><em>ThoughtSpot</em></a><em> </em>a data analytics app which provides visual reporting components that can be embedded inside any app.</p><p>You can learn more about ThoughtSpot APIs for developers <a href="https://developers.thoughtspot.com/docs">here</a>.</p><h3>Sync host-app scroll-bar with iframe scroll-bar</h3><p>Whenever the hostPage is scrolled, an event is triggered via adding a listener to the <strong>scroll event</strong> in the host Application. The payload of the hostEvent ( <strong>HostEvent.EmbedScroll </strong>) would contain the exact offSet in y axis that the iframe has to be scrolled.</p><blockquote>hostEvents in ThoughtSpot are postMessage communications sent from the host application to the embedded ThoughtSpot application</blockquote><h4>Explanation</h4><ul><li>As you scroll, the parent page sends a hostEvent “EmbedScroll” to the iframe.</li><li>iframe’s top margin adjusts based on the parent scroll position.</li><li>Payload (scrollY) tells the iframe how much to scroll within itself.</li></ul><h4><strong><em>Detailed Implementation</em></strong></h4><p>These lines set up the iframe to have a height equal to the browser’s viewport height and adjust the parent document’s height to fit the combined height of pageHeight and pinBoardHeight(liveboard), minus the visible portion of the viewport. This ensures the iframe appears as a fullscreen component within the viewport.</p><pre>this.iFrame.style.height = `${window.innerHeight}px`;<br>document.body.style.height = `${pageHeight + pinBoardHeight - viewPortHeight}px`;</pre><p>This block initialises the scroll event listener, capturing important metrics each time the user scrolls the parent page. offsetTopClient measures the position of the iframe relative to the top of the document, scrollTopClient records the current scroll position, and viewPortHeight &amp; iframeHeight store the viewport height and iframe’s intended height.</p><pre>window.addEventListener(&#39;scroll&#39;, () =&gt; {<br>var offsetTopClient = this.iFrame.offsetTop;<br>var scrollTopClient = window.scrollY;<br>var viewPortHeight = window.innerHeight;<br>var iframeHeight = pinBoardHeight;</pre><p>If the parent page has been scrolled beyond the starting point of the iframe (scrollTopClient — offsetTopClient &gt; 0), this code adjusts the iframe’s top margin to maintain a smooth scrolling experience. The Math.min condition ensures the margin adjustment does not exceed the scrollable height of the iframe (iframeHeight — viewPortHeight), maintaining continuity of the scroll flow.</p><pre>if (scrollTopClient - offsetTopClient &gt; 0) {<br>this.iFrame.style.marginTop = `${Math.min(scrollTopClient - offsetTopClient, iframeHeight - viewPortHeight)}px`;<br>}</pre><p>This block checks if the user has scrolled past the top of the iframe but hasn’t yet reached the end. During this condition, it triggers a HostEvent.EmbedScroll event, passing the scroll position as data (scrollY). This ensures the iframe content scrolls in sync with the parent document’s scroll.</p><pre>if (scrollTopClient - offsetTopClient &gt; 0 &amp;&amp; scrollTopClient - offsetTopClient &lt; iframeHeight - viewPortHeight) {<br>this.trigger(HostEvent.EmbedScroll, { scrollY: scrollTopClient - offsetTopClient });<br>}</pre><p>If the parent page is scrolled above the starting point of the iframe (scrollTopClient — offsetTopClient &lt; 0), the event is triggered with scrollY: 0. This keeps the iframe at the topmost position, fully visible and not scrolled.</p><pre>else if (scrollTopClient - offsetTopClient &lt; 0) {<br>this.trigger(HostEvent.EmbedScroll, { scrollY: 0 });<br>}</pre><p>When the parent page is scrolled beyond the height of the iframe (scrollTopClient — offsetTopClient &gt;= iframeHeight — viewPortHeight), this code sets the iframe’s scroll position to its maximum scrollable point, ensuring it appears fully scrolled and smoothly aligned with the parent document’s scroll flow.</p><pre>else if (scrollTopClient - offsetTopClient &gt;= iframeHeight - viewPortHeight) {<br>this.trigger(HostEvent.EmbedScroll, { scrollY: iframeHeight - viewPortHeight });<br>}</pre><p><strong>Complete sample code :-</strong></p><pre>this.iFrame.style.height = `${window.innerHeight}px`;<br>document.body.style.height = `${pageHeight + pinBoardHeight - viewPortHeight}px`;<br>window.addEventListener(&#39;scroll&#39;,()=&gt;{<br>var offsetTopClient = this.iFrame.offsetTop;<br>var scrollTopClient = window.scrollY;<br>var viewPortHeight = window.innerHeight;<br>var iframeHeight = pinBoardHeight<br>if(scrollTopClient - offsetTopClient &gt; 0) {<br>this.iFrame.style.marginTop = `${Math.min(scrollTopClient - offsetTopClient,iframeHeight - viewPortHeight)}px`;<br>}<br>if(scrollTopClient - offsetTopClient &gt; 0 &amp;&amp; scrollTopClient - offsetTopClient &lt; iframeHeight - viewPortHeight) {<br>this.trigger(HostEvent.EmbedScroll,{scrollY:scrollTopClient-offsetTopClient});<br>}<br>else if(scrollTopClient - offsetTopClient &lt; 0) {<br>this.trigger(HostEvent.EmbedScroll,{scrollY:0});<br>}<br>else if(scrollTopClient - offsetTopClient &gt;= iframeHeight - viewPortHeight) {<br>this.trigger(HostEvent.EmbedScroll,{scrollY:iframeHeight - viewPortHeight})<br>}<br>});</pre><h4>Disadvantages of This Approach</h4><ol><li><strong>Potential for Scrollbars</strong>: If the offset calculation isn’t precise or if the content inside the iframe changes dynamically, you can still end up with scrollbars.</li><li><strong>Performance Overhead</strong>: Continuously recalculating and resetting the height on every window resize event might be costly, especially if the page has multiple embedded elements.</li><li><strong>Cross-Browser Inconsistencies</strong>: Different browsers handle viewport measurements slightly differently (e.g., the difference between document.documentElement.clientHeight vs. window.innerHeight), leading to potential miscalculations.</li><li><strong>Content Overflows</strong>: If the embedded dashboard has its own internal scrolling or expands due to user interactions, the initial fixed calculation might not suffice.</li></ol><blockquote>Since the <strong>fullHeight Solution</strong> has already been implemented, ThoughtSpot doesn’t provide support for <strong>sync scroll-bars solution</strong></blockquote><h3>Full Height Solution</h3><h4><strong>Implementation details :-</strong></h4><ul><li>The iFrame height should be recalculated and updated whenever a navigation event occurs within the embedded application.</li><li>The dynamic resizing mechanism ensures that all embedded content is fully visible within the iFrame without introducing an additional scroll bar, thereby eliminating the double-scroll issue.</li><li>Height adjustments is applied via postMessage communication or appropriate event listeners to detect content changes and trigger height recalculations.</li></ul><h3><strong>Handling modals in FullHeight</strong></h3><p>If unhandled any modal that opens up would render at the centre of the iframe, which could be outside the viewport. So for this we would need to recalculate the centre of the iframe’s viewport.</p><h4>Detailed implementation</h4><p><strong>a. Calculating iframeVisibleViewPort and iframeOffset</strong></p><p>When the iframe is above the viewport, the visible portion is reduced. If the iframe is partially visible or scrolled past, adjustments are made to calculate the portion of the iframe currently visible.</p><p><strong>iframeVisibleViewPort:</strong> height of iframe that is currently in the viewport of the host application.</p><p><strong>iframeOffset:</strong> distance from the top boundary of the iframe to the first visible pixel of the content being displayed inside the iframe that is within the viewport.</p><pre>var offsetTopClient = this.iFrame.offsetTop;<br>var scrollTopClient = window.scrollY;<br>offsetTopClient: The distance of the iframe from the top of the document. scrollTopClient: The current scroll position of the main document.<br>var viewPortHeight = window.innerHeight;<br>var iframeHeight = this.iFrame.innerHeight;<br>var iframeScrolled = scrollTopClient - offsetTopClient;<br>var iframeVisibleViewPort, iframeOffset;<br><br>if(iframeScrolled &lt; 0) {<br>iframeVisibleViewPort = viewPortHeight - (offsetTopClient - scrollTopClient);<br>iframeVisibleViewPort = Math.min(iframeHeight, iframeVisibleViewPort);<br>iframeOffset = 0;<br>} else {<br>iframeVisibleViewPort = Math.min(iframeHeight - iframeScrolled, viewPortHeight);<br>iframeOffset = iframeScrolled;<br>}</pre><p><strong>b. Positioning the Modal</strong></p><p>The modal is centered relative to the <strong>currently visible portion of the iframe</strong>. The calculation ensures the modal is always within the iframe’s boundaries, avoiding rendering issues when partially or fully scrolled out of view.</p><pre>iframeCenter = iframeOffset + iframeVisibleViewPort / 2;<br>var modalHeight = 400;<br>var modalTop;<br>modalTop = Math.max(0, iframeCenter - modalHeight / 2);<br>modalTop = Math.min(iframeHeight - modalHeight / 2, modalTop);</pre><p><strong>Complete sample code :-</strong></p><pre>var offsetTopClient = this.iFrame.offsetTop;<br>var scrollTopClient = window.scrollY;<br>var viewPortHeight = window.innerHeight;<br>var iframeHeight = this.iFrame.innerHeight;<br>var iframeScrolled = scrollTopClient - offsetTopClient;<br>var iframeVisibleViewPort, iframeOffset, iframeCenter;<br>if(iframeScrolled &lt; 0) {<br>iframeVisibleViewPort = viewPortHeight - (offsetTopClient - scrollTopClient) ;<br>iframeVisibleViewPort = Math.min(iframeHeight,iframeVisibleViewPort);<br>iframeOffset = 0;<br>}<br>else {<br>iframeVisibleViewPort = Math.min(iframeHeight - iframeScrolled,viewPortHeight);<br>iframeOffset = iframeScrolled;<br>}<br>iframeCenter = iframeOffset + iframeVisibleViewPort/2;<br>var modalHeight = 400;<br>var modalTop;<br>modalTop = Math.max(0,iframeCenter - modalHeight/2);<br>modalTop = Math.min(iframeHeight - modalHeight/2,modalTop);</pre><h4>Why This Approach Works</h4><ul><li><strong><em>Dynamic Height Adjustment:</em></strong><em> The iframe’s height is continually updated based on content changes via postMessage communication or event listeners, ensuring the entire content is always visible.</em></li><li><strong><em>Improved User Experience:</em></strong><em> Eliminates double-scroll issues by maintaining a single scroll mechanism, improving accessibility and responsiveness.</em></li><li><strong><em>Modal Handling:</em></strong><em> Accurately positions modals even when the iframe content is scrolled, ensuring they appear centered within the visible viewport.</em></li></ul><h4><strong>Lazy loading of visualisations</strong></h4><ul><li>Lazy loading of visualisations improves initial load times and application performance by loading only essential components first (here only the visualisations that are in liveboard page’s viewport), allowing users to interact with the app sooner.</li><li><strong>Trade-offs with Full Height</strong>: Lazy Loading is not currently implemented for the fullHeight property. When fullHeight is enabled, all visualisations on the liveboard load simultaneously, which can lead to performance issues due to multiple warehouse queries being executed at once.</li></ul><h3>How can you use Full Height Solution</h3><p>To use this fullHeight feature, simply pass the fullHeight: true configuration while creating your embed instance.</p><pre>const embed = new LiveboardEmbed(&#39;#embed&#39;, {<br>// other liveboard view config<br>fullHeight: true,<br>});</pre><p>The iframe’s height will automatically adjust to match the content, and modals will be properly centred even when partially scrolled out of view.</p><h3>Statistics on Feature Usage</h3><p>The data for the past 6 months reveals a consistent interest among users, with notable peaks in January and February 2025, where unique user counts reached approximately 18.15K and 18.7K, respectively. This indicates a strong adoption of the feature. Overall, the average unique users per month stands at 16.0K, reflecting a solid engagement level.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r62E1WWWMXwPCenySgdMfw.png" /></figure><h3>Useful Links</h3><ul><li><a href="https://www.thoughtspot.com/"><strong>Try ThoughtSpot for Free</strong></a> — Explore ThoughtSpot with a free trial.</li><li><a href="https://github.com/thoughtspot/visual-embed-sdk"><strong>Visual Embed SDK</strong></a> — The official GitHub repository for ThoughtSpot’s Visual Embed SDK.</li><li><a href="https://developers.thoughtspot.com/docs/tsembed"><strong>Developer Documentation</strong></a> — Comprehensive guides and API references for embedding ThoughtSpot.</li><li><a href="https://discord.gg/FAJ96kCJ"><strong>Discord</strong></a> — Join Our Discord Community! Connect with fellow ThoughtSpot developers, share insights, and collaborate on exciting projects</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=470891a8d807" width="1" height="1" alt=""><hr><p><a href="https://medium.com/thoughtspotdev/how-to-avoid-double-scroll-bar-while-embedding-470891a8d807">How to avoid double scroll bars when embedding on the Web</a> was originally published in <a href="https://medium.com/thoughtspotdev">thoughtspotdev</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>