Skip to content

Commit f87dfd1

Browse files
committed
feat: show new images on hover from image ribbon
1 parent 9cbc2e6 commit f87dfd1

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/LiveDevelopment/BrowserScripts/RemoteFunctions.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,7 +1965,7 @@ function RemoteFunctions(config = {}) {
19651965
19661966
.phoenix-ribbon-row {
19671967
display: flex !important;
1968-
gap: 12px !important;
1968+
gap: 2px !important;
19691969
align-items: center !important;
19701970
height: 100% !important;
19711971
}
@@ -2197,6 +2197,27 @@ function RemoteFunctions(config = {}) {
21972197
img.alt = image.alt_text || 'Unsplash image';
21982198
img.loading = 'lazy';
21992199

2200+
// this is the original image, we store it so that we can show new images on hover
2201+
const originalImageSrc = this.element.src;
2202+
// we also store its dimensions to show the new image with the same dimension
2203+
const computedStyle = window.getComputedStyle(this.element);
2204+
const originalWidth = computedStyle.width;
2205+
const originalHeight = computedStyle.height;
2206+
const originalObjectFit = computedStyle.objectFit;
2207+
2208+
// show hovered image along with dimensions
2209+
thumbDiv.addEventListener('mouseenter', () => {
2210+
this.element.style.width = originalWidth;
2211+
this.element.style.height = originalHeight;
2212+
this.element.style.objectFit = originalObjectFit || 'cover';
2213+
this.element.src = image.url || image.thumb_url;
2214+
});
2215+
2216+
// show original image when hover ends
2217+
thumbDiv.addEventListener('mouseleave', () => {
2218+
this.element.src = originalImageSrc;
2219+
});
2220+
22002221
thumbDiv.appendChild(img);
22012222
rowElement.appendChild(thumbDiv);
22022223
});

0 commit comments

Comments
 (0)