PDA

View Full Version : Resolved FIXED: Image Size & Position



Dirt_Diver
10-28-2011, 04:07 AM
Can someone help me with this code?

This goes to an image hover script and it works but it displays the image as full size. So for example if the original image is 800 pixels, the hovered image will show that. Also it shows my image at the point of the mouse.

What I would like to do is display the image at a Max of 450 pixel (on the longest side, tall or wide) and have it displayed in the top right corner of the screen.

Can someone help me please???


function pos(img, e) {
var cX, cY;
if(e) {
img.setAttribute('cX', cX = e.clientX);
img.setAttribute('cY', cY = e.clientY);
} else {
cX = parseInt(img.getAttribute('cX'));
cY = parseInt(img.getAttribute('cY'));
}
if(!img.naturalHeight) {
return;
}
var maxW = Math.min(window.innerWidth, document.documentElement.clientWidth);
var maxH = Math.min(window.innerHeight, document.documentElement.clientHeight);
img.style.maxWidth = maxW + 'px';
img.style.maxHeight = maxH + 'px';
var w = img.clientWidth;
var h = img.clientHeight;
img.style.left = Math.min(maxW - w, Math.max(0, cX + (cX > maxW/2 ? -w -20 : 20))) + 'px';
img.style.top = Math.min(maxH - h, Math.max(0, cY + (cY < maxH/2 ? 20 : -h -20))) + 'px';
}

Dirt_Diver
10-28-2011, 02:58 PM
I got it fixed