Ketola
Member
When using a Fixed Width Style showing a full-size version of an embedded image in a post causes the picture to overflow page borders. For a demo see this post and make sure you choose the Fixed Width Style first.
This is especially problematic if the dimensions of the attachment pictures aren't limited at all.
Suggestions for fixing:
The image size is limited to width of the viewport (height can be larger), the left offset of the full size image is calculated based on the center of the page, and the picture is zoomed out from it's original position.
For a demonstration of the implementation, see this thread at our forum.
This is especially problematic if the dimensions of the attachment pictures aren't limited at all.
Suggestions for fixing:
- center the zoomed image on page and make sure it fits to page borders
- wrap the image in an A tag to allow users to ctrl-click to a full size version
HTML:
toggleFullSize: function(e)
{
var currentWidth = this.$image.width(),
offset, cssOffset, cssOffsetTargetLeft, scale,
scrollLeft, scrollTop,
layerX, layerY,
$fullSizeImage,
speed = window.navigator.userAgent.match(/Android|iOS|iPhone|iPad|Mobile Safari/i) ? 0 : XenForo.speed.normal,
easing = 'easeInOutQuart';
if (this.actualWidth > currentWidth)
{
offset = this.$image.offset();
cssOffset = offset;
layerX = e.pageX - offset.left;
layerY = e.pageY - offset.top;
// Limit zoomed image width to document width
if(this.actualWidth > $('html').width()) {
this.actualWidth = $('html').width();
}
scale = this.actualWidth / currentWidth;
// Center image horizontally
cssOffsetTargetLeft = ($('html').width()-this.actualWidth)/2;
if (XenForo.isRTL())
{
cssOffset.right = $('html').width() - cssOffset.left - currentWidth;
cssOffset.left = 'auto';
}
$fullSizeImage = $('<img />', { src: this.$image.attr('src') })
.addClass('bbCodeImageFullSize')
.css('width', currentWidth)
.css(cssOffset)
.click(function()
{
$(this).remove();
$(XenForo.getPageScrollTagName()).scrollLeft(0).scrollTop(offset.top);
})
.appendTo('body')
.animate({ width: this.actualWidth, left: cssOffsetTargetLeft, top: cssOffset.top }, speed, easing);
// Zoom image from scaled down image's top offset to maximum width
// remove full size image if an overlay is about to open
$(document).one('OverlayOpening', function()
{
$fullSizeImage.remove();
});
if (e.target == this.$image.get(0))
{
// scrollLeft = offset.left + (e.pageX - offset.left) * scale - $(window).width() / 2;
// scrollTop = offset.top + (e.pageY - offset.top) * scale - $(window).height() / 2;
// Scroll top to original image's top position. The original scrollTop scrolls pretty much where it wants to
// Scroll left to full size image's left offset
scrollLeft = cssOffsetTargetLeft;
scrollTop = offset.top;
}
else
{
scrollLeft = offset.left + (this.actualWidth / 2) - $(window).width() / 2;
scrollTop = offset.top + (this.$image.height() * scale / 2) - $(window).height() / 2;
}
$(XenForo.getPageScrollTagName()).animate(
{
scrollLeft: scrollLeft,
scrollTop: scrollTop
}, speed, easing, $.context(function()
{
var tooltip = this.$image.data('tooltip');
if (tooltip)
{
tooltip.hide();
}
}, this));
}
},
The image size is limited to width of the viewport (height can be larger), the left offset of the full size image is calculated based on the center of the page, and the picture is zoomed out from it's original position.
For a demonstration of the implementation, see this thread at our forum.
Upvote
1