Results 1 to 2 of 2

Thread: FIXED: Image Size & Position

  1. #1
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default FIXED: Image Size & Position

    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???

    Code:
    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';
    	}
    Last edited by Dirt_Diver; 10-28-2011 at 02:58 PM. Reason: Fixed
    ___________________________________

    Still working on it!

  2. #2
    Join Date
    Aug 2008
    Location
    Smiths, AL
    Posts
    164
    Thanks
    30
    Thanked 5 Times in 5 Posts

    Default

    I got it fixed
    ___________________________________

    Still working on it!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •