How To Resize / Reset Dimension Of Image To Fit In DIV
Oct 19, 2010
I've written some javasript code to resize an image tag. While the page loads the image tag is display: none so a large image wont break the stylesheet before I have a chance to shrink it. onload I call function load1 and you can follow the rest from the code below. This is working in Firefox and Chrome and appears to be doing absolutely nothing in any version of IE.
Javascript after </html> tag:
<script type="text/Javascript">
function load1() {
imageLoaded();
document.getElementById("confImage").style.display = "block";
} function imageLoaded() {
var iW = document.getElementById("confImage").width;
var iH = document.getElementById("confImage").height;
changeImageSize(iW, iH);
} function changeImageSize(iW, iH) {
if (iW > 460 || iH > 460) {
reset dimension of image to fit in div
var multiply = 0;
if (460 / iW < 460 / iH) {
multiply = myFloor(460 / iW, 3);
} else {
multiply = myFloor(460 / iH, 3);
}
document.getElementById("confImage").width = multiply * iW;
document.getElementById("confImage").height = multiply * iH;
}}
function myFloor(n, pos) {
n = "" + n;
if (n.length < n.indexOf('.') + pos + 1) {
return parseInt(n);
} else {
return n.substr(0, n.indexOf('.') + pos);
}}
</script>
View 3 Replies
ADVERTISEMENT
Jul 15, 2010
How can I get the real image dimension with javascript? code...
However this only seems to be working sometimes in Opera . No luck in firefox or chrome (dunno about IE)
Anyways to do it?
I thought of maybe using an Ajax call, but then the imgLink cannot be a relative position, which would be difficult to parse due to some address like http://example.com/directory as i tried to get everything before the last /
View 7 Replies
View Related
Sep 19, 2011
I'm using serialscroll jquery plugin from ariel Flesler on this page : http://goo.gl/HMNUX the width of the container (#slideshow) is 100% of the window's width. everything is fine until the user resize the window. Then the pictures are not in the right position anymore. should reset the "offset" setting of the plugin on resize. I tried this, but it doesn't work :
[Code]...
View 5 Replies
View Related
Mar 6, 2006
I am trying to reset the width of the image while loading:
<img src='s.jpg' onload="javascript:if(this.width>120)
this.width=100;">
It's ok. And then I am going to make the code more flexible
<img src='s.jpg'
onload="javascript:if(this.width>javascript:window.document.body.offsetWidth)
this.width=50;">
this time, I compare the image width with the offsetWidth, however, I
found the code above didn't work no matter how small offsetWidh is
made.
BTW, I would like to make the width of image fit the current width of
the document, only HTML works fine under IE
<img src='s.jpg' width="100%" LEFTMARGIN=10>
But when applying the above code to the image of small size, it always
try to strech the image ,which will then look very bad.
I am trying to apply the code on condiiton: when the width of image is
smaller than a given value, do nothing; otherwise add "width=100%
LEFTMARGIN=10". Here is the javascript I tried
<img src='s.jpg' onload="javascript:if(this.width>100)
javascript:document.write('WIDTH=100% LEFTMARGIN=10');">
However, it didn't give the result I want.
View 1 Replies
View Related
Feb 12, 2010
I have a photo gallery built with XML and PHP (pulling images from a client's Myspace albums).The gallery works fine, displays thumbnails and captions, paginates properly, etc.The whole thing is loaded by AJAX into a div, which complicates things a bit, but it works.When a visitor clicks a thumbnail, the full-sized image displays in a div overlay on top of the gallery div.The overlay is hidden until a thumbnail is clicked, when it is toggled to "visibility:visible". When the overlay "close" link is clicked, the overlay is hidden again.That also works. Some of the images are too large to display properly inside the div without throwing off the layout, so I had to set a max height and width.I can't just use CSS to set the dimensions or it'll size EVERY image to those dims, and the photos are all different sizes...some wider, some longer.So I used javascript to check the image size when the thumbnail is clicked.
All of that worked.(Although strangely, if I try to toggle the visibility as part of the function rather than putting it into the link, it doesn't work!)The problem is that once the dimensions of "img1" are set, they STAY that size even when the next thumbnail is clicked.So if the first image is 800px tall, the script crops it to 640px...then the next image may only be 400px pix tall but it displays as 640px high, making it distorted.I tried to add a "resetImgSize" function to the "close" link in the overlay, setting the img1 dimensions back to 2px x 2px when the overlay is closed, but the same thing happens...Once the img1 dimensions are set to 2x2px, they stay that way even when a new thumbnail is clicked.
View 10 Replies
View Related
Jul 20, 2005
In one folder i've put all pics, but they are not all the same size. i've
got as many links as pics and clicking on link popUp opens showing that pic.
now, i would like to have one function that opens popUp window but in
different dimension for different pic....
View 5 Replies
View Related
Apr 10, 2009
I want to make a nice floating bar at the bottom of the screen, which hovers about 15px from the bottom. I am doing this to make a site look good in small and big resolutions. The minimum height for the bar to hover is 600px about, if the window is smaller, it is still there so it doesn't go into the content, if the window is bigger, it will follow the resize and be at the bottom still. It is obviously absolutely positioned, and also centered using some javascript (getting the width of the window).The second function is called in the header and positions the bar. The last two document.get things are just for testing so I can see the height in px somewhere. This works fine in IE. If I resize the window, making it shorter, everything goes as planned, and I can see the pixel count dropping in the header where it is displayed. However, in FF it does not work.
The weird thing is this. If I resize by a small amount, less than 10px, it works fine. However, I can not resize by more than 10px! If I do, the window height shown in the top still drops by only 10px.So if my window is 1000px tall, and I close it to say 500px, the value of the height will still be 990px. If I then resize it to any where higher than the 500px, say 550px, the javascript still sees it as making it smaller, since it says the height is 990px, therefore, the window height goes down to 980px. If I shrink the window to 500px and reload everything is fine, if I make it bigger, it works in both browsers. I am thinking that this could be a problem which is like "sampling rate" in music. When in IE I expand or shrink the window I can see the pixel count drop continuously and the bar floating down as I move the window, as if it was "sampled" every 0.05 seconds or something. In FF, shrinking is not working, but if I expand the window the pixel count doesn't change and the bar doesn't change place until I stop resizing (let go of the mouse button), as if it was sampled once, when I stop, so the problem maybe is related?
View 1 Replies
View Related
Jul 23, 2005
I have the following code in a .net page:
<IMG alt="photo" src="Imagesa.gif" height="70" width="70">
When the page opens, the window is not maximized. So when I maximize
the window, the image disappears. If I restore down, the image is
still gone. All the darn coding on this page and I'm getting stuck on
HTML!
View 3 Replies
View Related
Nov 9, 2010
Anyone know how to detect the dimension of a browser by jQuery? And how to detect when the dimension is changed?
View 6 Replies
View Related
Mar 1, 2010
I am trying to dynamically resize an image. Here is my code:
<img border="0" src="images/right.gif" width="16" height="100" name="right">
<SCRIPT Language=Javascript>
<!--
function ChangeImgSize(){
[Code]....
The image does not get resized. I've been testing the page on current browsers (IE 8, Firefox, Chrome). I'm certain I'm doing something newbish, I don't really know Javascript all that well.
View 5 Replies
View Related
Apr 5, 2011
how to veiw this eval's out put?
function doButtons(picimage) {
eval("document['picture'].src = " + picimage + ".src");
}
<?php
// to change the image size within the web page
function imageResize($width, $height, $target) {
//takes the larger size of the width and height and applies the formula accordingly...
//this is so this script will work dynamically with any size image
[Code]....
View 3 Replies
View Related
Jan 6, 2006
I have to display an image in a fixed spot on my web page. The images are submitted by users, and I have no control over their size (width and height). If the image is wider than 130 pixels, I need to display it with an IMG WIDTH=130 to fit the spot. If the image is less than 130 pixels, I want to display it as is.
Is there a way with Javascript to retrieve the width of the image before the image is displayed by the browser? I know I can preload the image, can I then look at the width before the HTML displays it?
View 6 Replies
View Related
Jul 24, 2007
I want to know how to auto resize an image when the mouse cursor hover
or point onto an image without clicking it.
is there a tutorial out there? or could you show me the link for it.
View 2 Replies
View Related
Oct 24, 2010
how to resize a div containing some text by setting a width and height so it would stretch to fill that area like an <img> tag? E.g. when you set the width and height attribute of an image, it resizes the image to fill that area. I do not wish to send a request to a php script to build an image containing the text since it will be slow and affect the scalability of the web app. Oh, and I would preferably not like to use html5 because it is a requisite that I need compatibility with ie7+ (and firefox/chrome).
View 5 Replies
View Related
Oct 9, 2011
I have a table (not in a form) that has several input text boxes. I want to have a reset button that acts like the form RESET button. I thought I would use the following jQuery method:
Here's my reset button code:
Here's one of my table input lines:
I thought this would be simple, but I can't seem to figure out how to target the text that the user types into an input field before he/she decides to "reset" and start over.
I'm thinking that my problem is that I can't find the correct syntax for my line: $('input.firstname').value('')
View 7 Replies
View Related
Jul 20, 2005
I have a problem trying to load an image without the image resizing
itself to fit into the window. My simple javascript is as follows:
function viewImage(filename)
{
features = "height=500, width=670, scrollbars=yes, resizable=yes";
photo = window.open(filename, "Preview", features);
}
View 6 Replies
View Related
Jan 18, 2011
I need to have an image of a heart on a site that beats, so essentially it expands and contracts. Whats the best animation effect for this? Should I use .animate to resize the image?
View 7 Replies
View Related
Aug 5, 2011
I have two images, one on top of another. I would like it so that if you mouse over the image on top (imgB), this image would resize and expand. I have tried playing with jQuery's animate() and height/width properties, but these just crop the image as oppose to resizing them.
<div id="imgA" style="background-image:url(aq.jpg); width:1000px; height:400px;">
<div id="imgB" style="background-image:url(wmc.png); width:200px; height:200px;"></div>
</div>
[code]....
View 1 Replies
View Related
Oct 13, 2011
Basically, i have an image that i want it to be resized when i maximize and change browser size, so it is always centered. I have to use only javascript. I tried many window.resize functions but nothing works. Lets say the image is called 0000.jpg.
View 2 Replies
View Related
Oct 13, 2011
I have an image that i want it to be resized when i maximize and change browser size. I have to use only javascript. I tried many window.resize functions but nothing works. Lets say the image is called 0000.jpg.
View 3 Replies
View Related
May 4, 2009
I am trying to make a javascript utility where the user can resize and drag an image. A slider contols the size of image from 0% to 200%. And also the image is draggable and the x and y coordinates of the image are immediately reflected on a text box in the page.
I think that this is possible with jquery or other javascript libraries. But was looking for some direction where I can find the best tutorial or examples.
View 3 Replies
View Related
Dec 13, 2003
I have a large image that is located in a folder called "large_image" .
I want to use javascript to resize that image to a size so that it would fit to page before it is sent to printer. Is that possible.
View 2 Replies
View Related
Aug 17, 2011
I have a situation where I'm sending full sizes images to new windows from linked thumnails. Using _blank, the window is rendering at a very small size, and the image scales to that size on some browsers.
I want the window to be larger when it comes up, and the image to display maximized (not scaled). I know how to resize the window from javascript in link-side docs, but not in linking-side docs.and no idea how to max the presentation of the image.
View 1 Replies
View Related
Feb 3, 2010
I got this Resize Image BBCode here. It is used for a Forum called Zetaboards, where I can just put it in my Admin Control Panel to make it work for my whole forum.What does the code do?With this BBCode, members are able to insert images to their posts and also are able to resize the images.[code]Can someone please help to make the code work correctly so the images are resized properly on Firefix, IE, and Google Chrome?
View 1 Replies
View Related
Jan 6, 2012
i am working on a project that will involve displaying a long list of product information. this will include images and description of the product. knowing fully well that users must have uploaded images with different dimensions, i want to display the images such that they will all have same dimensions without having some of them lose aspect ratio. i want it to look like the way facebook displays facepile (your friends), it may only hide a portion of it,
View 1 Replies
View Related
Aug 12, 2011
I was wondering if there is a way to use Jquery to reduce the amount of images I use on my company website as well as resize them depending on the page they're displayed on. It's just that I feel that's it's very tedious creating 5 or 6 formats for each campaign each with it's own dimensions depending on the page and unfortunately my company doesn't want to implement a Backoffice fed site, which means I have to do it all manually.
View 3 Replies
View Related