@@ -208,6 +208,23 @@ function RemoteFunctions(config = {}) {
208208 ) ;
209209 }
210210
211+ /**
212+ * this function checks whether the image gallery overlaps the image element
213+ * because if it does we scroll the image element a bit above so that users can see the whole image clearly
214+ * @param {DOMElement } element - the image element
215+ * @param {DOMElement } imageGalleryElement - the image gallery container
216+ */
217+ function scrollImageToViewportIfRequired ( element , imageGalleryElement ) {
218+ let elementRect = element . getBoundingClientRect ( ) ;
219+ let galleryRect = imageGalleryElement . _shadow . querySelector ( '.phoenix-image-ribbon' ) . getBoundingClientRect ( ) ;
220+
221+ // this will get true when the image element and the image gallery overlaps each other
222+ if ( elementRect . bottom >= galleryRect . top ) {
223+ const scrollValue = window . scrollY + ( elementRect . bottom - galleryRect . top ) + 10 ;
224+ window . scrollTo ( 0 , scrollValue ) ;
225+ }
226+ }
227+
211228 // Checks if an element is actually visible to the user (not hidden, collapsed, or off-screen)
212229 function isElementVisible ( element ) {
213230 // Check if element has zero dimensions (indicates it's hidden or collapsed)
@@ -269,6 +286,7 @@ function RemoteFunctions(config = {}) {
269286 } else {
270287 imageGallerySelected = true ;
271288 _imageRibbonGallery = new ImageRibbonGallery ( element ) ;
289+ scrollImageToViewportIfRequired ( element , _imageRibbonGallery ) ;
272290 }
273291 }
274292
@@ -3618,6 +3636,7 @@ function RemoteFunctions(config = {}) {
36183636 if ( element && element . tagName . toLowerCase ( ) === 'img' && imageGallerySelected ) {
36193637 if ( ! _imageRibbonGallery ) {
36203638 _imageRibbonGallery = new ImageRibbonGallery ( element ) ;
3639+ scrollImageToViewportIfRequired ( element , _imageRibbonGallery ) ;
36213640 }
36223641 }
36233642
0 commit comments