JavaScript - How To Show Image In The Image Box Without Stretching Its Original Size Of The Image
i have image button i need to display image .if the size of the image button is 100*100 and image size is 50*50 .the remaining space of the image button should be empty.the image should not stretch.
can any one guide me i am new to programming Thanks in advance!!! Similar TutorialsHello I was looking for a javascript code to show an image in full size on moueover, I use this script on the site Code: function ShowPicture(id,Source) { if (Source=="1"){ if (document.layers) document.layers[''+id+''].visibility = "show" else if (document.all) document.all[''+id+''].style.visibility = "visible" else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "visible" } else if (Source=="0"){ if (document.layers) document.layers[''+id+''].visibility = "hide" else if (document.all) document.all[''+id+''].style.visibility = "hidden" else if (document.getElementById) document.getElementById(''+id+'').style.visibility = "hidden" } } CSS code i use: Code: <style type="text/css"> #Style { position:absolute; visibility:hidden; border:solid 1px #CCC; padding:5px; } </style> On the site to to body I put this html code: Code: <a href="#" onMouseOver="ShowPicture('Style',1)" onMouseOut="ShowPicture('Style',0)">Click Here To Show Image</a> <div id="Style"><img src="/sites/default/files/peroulades.jpg"></div> When Im hovering over the link image is shown full size, Problem: if you take a look: http://www.online-dovolenka.sk/dovolenka_korfu if hover over both links "Click Here To Show Image" you will see same image, but I put two different images? where is the problem? any ideas? Code: <a href="#" onMouseOver="ShowPicture('Style',1)" onMouseOut="ShowPicture('Style',0)">Click Here To Show Image</a> <div id="Style"><img src="/sites/default/files/peroulades.jpg"></div> <a href="#" onMouseOver="ShowPicture('Style',1)" onMouseOut="ShowPicture('Style',0)">Click Here To Show Image</a> <div id="Style"><img src="/sites/default/files/pantokrator.jpg"></div> QUESTION 1: Hello. I would like to know if this is possible with Javascript, and if yes, if someone can please provide me with the code or point me in the right direction. Let me start of by saying that this is for an eBay listing. I know that they accept basic / limited javascript and if what I am asking is possible, I hope that it can work on eBay listings. I would like to know if it's possible to determine the dimensions of an image with Javascript from an Image url, and to then resize it or not based on the the size of the image. So, let's say this is the URL: www.adomainname.com/image.jpg and let's say that image is 1400 px x 1400 px. I would first like the javascript code to detect that size. I also would like the maximum dimension for any side of the image to be 600 px. If both sides of the image are over 600 px, for both sides to be reduced proportionally to 600 px or lower. If any one side of the image is larger than 600 px, the image is to be resized to 600 px or lower. If both sides are under 600 px, the image is to not be reduced. It would also be nice if it can detect whether the image is portion or landscape based on I guess the larger side, because an image at 600 px in height might be too big, but in width might be o.k. So, in this example (the 1400 px by 1400 px), the image is to be resized to 600 px x 600 px. For an image that's 300 px x 500 px, it should remain as such. For an image that's 400 px x 700 px, it should be resized to 400 / (700 / 600) px by 600 px, which is approximately 343 px x 600 px. I have looked a bit into this and I see things being mentioned about the image being loaded first completely on the screen, or about using server side language like PHP, and so on, but like I said, keep in mind that this is for eBay, and so I am limited. Note: The part that I am most interested in is in being able to detect the size / dimensions of the image. QUESTION 2: On a side note, does anyone know if it's possible to have a Javascript enlarging function for images, in which when one clicks on an image, it is enlarged, but either in a popup window that's smaller than the one behind it, and possibly centered, or by making the background go dark and then bringing up the enlarged image (is the latter done with Javascript; I have seen this effect for a while now and have always wondered.) How do I show the default icon for pdf, doc, etc... else show the image? Code: Show the default icon for pdf, doc, etc... else show image. Default icon: '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' + The image: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0"></a>' + Attempted javascript onError but only certain browsers support that or it's my code. Code: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0" onerror="this.src=images/icons/' + sIcon + '.gif"></a>' + Any ideas? Needless to say, I am no coder! I dabble with it only when I have to. I have images/text linked to buttons that fade in “onclick” from “original” images/text . I’ve gotten this to work great with text or image but… I would like the images/text to fade out and return to “original” images/text after a time limit and or no mouse use. Here’s the code I have so far: Code: $(document).ready(function(){ $('.image1).click(function() { $('#original_image).fadeOut(300, function() { var the_image = $('#image1).html(); $(this).html(the_image).fadeIn(300); }); }); Thanks I am trying to write a custom BBcode for a forum I moderate. I don't have the licensing information because its not my forum and i am just a moderator. If anyone wants to verify the legitimacy of the forum I work for please PM me and I will try and get you any information I can. This code that I has works perfect in EditRocket, but when I add it to the custom BBcode the image does not resize. Original EditBucket Code: Code: <html> <head> <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> </head> <body> <img id="testimg" onload="show_confirm(testimg)" src="http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png"> </body> </html> vBulletin Custom BBcode: title: Test Image bbcode tag name: timage Replacement: Code: <script type="text/javascript"> function show_confirm(testimg) { var theImg = document.getElementById('testimg'); var theWidth = theImg.width; var theHeight = theImg.height; if (theWidth<250) { theImg.width = theWidth; theImg.height = theHeight; } else { theImg.width = 250; theImg.height = theHeight*(250/theWidth); } } </script> <body> <img id="testimg" onload="show_confirm(testimg)" src="{param}"> </body> Example: [timage]http://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Example.svg/600px-Example.svg.png[/timage] Description: Embed imaged inline with forum Option: no Greetings, First off - You can see my problem at psychopathgames.com I have an image stretched to fit as the page background in a DIV and the page content inside a seperate DIV. When you mouseover the links, the background changes to represent each link (as does the color of the link... but that is working fine). Trouble is, the images that are being pulled aren't fullsized as the main background is... it is being cut off by some code I can't figure out and isn't resizing. Please visit the site to see what talking about. Here is the code... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Psychopath Games</title> <style type="text/css"> html, body {height:100%; margin:0; padding:0;} #page-background {position:fixed; top:0; left:0; width:100%; height:100%;} #content {position: relative; z-index:1; padding:10px;} </style> <!--[if IE 6]> <style type="text/css"> html {overflow-y:hidden;} body {overflow-y:auto;} #page-background {position:absolute; z-index:-1;} #content {position:static;padding:10px;} </style> <![endif]--> <style type="text/css"> A:link {text-decoration: none} A:visited {text-decoration: none} A:active {text-decoration: none} A:hover {text-decoration: none} </style> <script language="JavaScript"> <!-- img0_on = new Image(100,11); img0_on.src="images/titlesred.png"; img0_off = new Image(100,11); img0_off.src="images/titles.png"; img1_on = new Image(130,11); img1_on.src="images/contactred.png"; img1_off = new Image(130,11); img1_off.src="images/contact.png"; img2_on = new Image(170,11); img2_on.src="images/talentred.png"; img2_off = new Image(170,11); img2_off.src="images/talent.png"; function over_image(parm_name) { document[parm_name].src = eval(parm_name + "_on.src"); } function off_image(parm_name) { document[parm_name].src = eval(parm_name + "_off.src"); } --> </script> <script type="text/javascript"> function showIt1(imgsrc) { newImage = "url(images/backgroundone.jpg)"; document.getElementById('content').style.backgroundImage = newImage; } function showIt2(imgsrc) { newImage = "url(images/backgroundtwo.jpg)"; document.getElementById('content').style.backgroundImage = newImage; } function showIt3(imgsrc) { newImage = "url(images/backgroundthree.jpg)"; document.getElementById('content').style.backgroundImage = newImage; } function hideIt() { newImage = "url(images/background.jpg)"; document.getElementById('content').style.backgroundImage = newImage; } </script> </head> <body> <div id="page-background"> <img src="images/background.jpg" width="100%" height="100%"> </div> <div id="content"> <center> <img src="images/title.png"> <br><br> <br> <table width="100%"> <tr> <td width="40%" align="right" valign="bottom"> <a href="titles.html" onmouseover="over_image('img0'); showIt1(this.src);" onmouseout="off_image('img0'); hideIt();"> <img src="images/titles.png" border="0" name="img0"> </a> <br> <br> <a href="contact.html" onmouseover="over_image('img1'); showIt2(this.src);" onmouseout="off_image('img1'); hideIt();"> <img src="images/contact.png" border="0" name="img1"> </a> <br> <br> <a href="talent.html" onmouseover="over_image('img2'); showIt3(this.src);" onmouseout="off_image('img2'); hideIt();"> <img src="images/talent.png" border="0" name="img2"> </a> <br> <br> </td> <td width="60%"> <center> <img src="images/eye.png"> </td> <tr> </table> </div> </body> </html> Hello, How can we calculate size of image by using javascript ? Thanks in advance I have a form that allows photos to be uploaded. I am using Perl to do this, and it works fine. Now I want to validate that the size of the image does not exceed a certain limit BEFORE it actually uploads. I can do that in Perl using something like the code below. But, I would rather do this in Javascript. I already have a routine that validates that the image file name does not contain embedded spaces. I would like to add this there. Can this be done in Javascript? Code: if ($ENV{'CONTENT_LENGTH'} > 100000) { print "SIZE EXCEEDS LIMIT!" } Hello everyone! I'm using Cut & Paste Plus Size image viewer ( http://www.javascriptkit.com/script/...geviewer.shtml ) , but I noticed some problem. When the large image is loaded initially, it's not always positioned on the center of the page. After that the script works just fine, until the browser is re-started. There is link to my page: http://www.accentironwork.com/yard%20decorations.html Script code is the http://www.accentironwork.com/plusimageviewer.js http://www.accentironwork.com/plusimageviewer.css I hope some body can help me. Thanks in advance! hello friends I'm a newbie.. I need a little help. Im using big images in my website. I want a javascript to toggle the image size from "Original size to fit with resolution of screen" and vice versa. It should be onclick function like this <img id="blahblah" src="myimage.jpg" onClick="resize();" /> I have followed all the correct steps to the Javascriptkit code for Plus Size Image Viewer: http://www.javascriptkit.com/script/...eviewer.shtml# Everything works fine but the Enlarge Image buttons are not where they should be. They should all appear at the bottom left of each individual image and are floating up. See example he http://www.bannerpen.ca/plastic_glossy.html Im not sure if the problem is the position or the display or none in the plusimageviewer.css script?? [CODE] .enlargecaption{ position: absolute; border: 1px dotted navy; font: normal 11px Arial; } .enlargecaption a{ display:block; background: lightgray; /*bg color of caption*/ padding: 3px; text-decoration: none; color: black; } .enlargecaption a:hover{ background: lightyellow; /*bg color of caption when mouse rolls over it*/ } .enlargebox{ position: absolute; border:1px solid gray; display:none; } .enlargebox .title{ background:gray; color:white; padding: 3px 2px; text-align: right; font:bold 14px Arial; } .enlargebox .title img{ cursorointer; cursor:hand; } [CODE] Hi. Sort of new to Javascript. I am implementing a zoom in feature, but actually tricking the user as a full screen image is simply being stretched. I plan to apply it to several pages, and don't really fancy working out the pixels for each. I believe that if you simply put width: 150% height 150% it will change the image size relative to the browser. I don't want that, I want it relative to the original image size. Could I do sort of height*1.5 or something? How would I write that if so? Thanks! Code: <script> $('#in').click(function() { $('#drag img').animate({ width: '150%', height: '150%', }, 5000, function() { // Animation complete. }); }); </script> Hi, I'm new here and trying to get some basics via examples. On this page http://www.gilariverwoodworks.com/kitchens.htm I have thumbnails in a table. Immediately below the table is a full sized image of thumb 1. I want to mouseover the thumbs and have the respective full size images swap. The thumbs remain as is. All the thumbs are the same file as the full size image but resized. If moused over, the new image should remain until the next thumb is moused over - ie no autoclose or return to original image. The viewer should be able to move around the page without having the image change til the next mouseover All the images are the same size Can someone offer or direct me to a script that will do this? TIA mr johnson Hi, fairly new to js. I have an image Code: <img src="uploading.png" /> I want to be able to have this hidden as default then when i submit my page <form action="handleupload.php"> it appears Hello! I am using this script for showing who is on the air. I would like to know if anyone has an idea how to make this show a picture file instead of text for who is on air. The script is great in that the gmt offset works. I would just rather have it show an image instead of text. Code: <span id = "dj" style="font-size:12px; font-weight:bold; font-family: Tahoma; color: #6600FF;"></span> <script type = "text/javascript"> function display() { var show = "No show scheduled at present"; var GMToffset = -5; // Your current GMT offset, whether Standard or Daylight var now = new Date(); var dy = now.getDay(); // day of week 0-6 now.setHours(GMToffset + now.getHours() + now.getTimezoneOffset() / 60); var hh = now.getHours(); var mn = now.getMinutes(); hh = hh + (mn/60); // minutes expressed as fractions of an hour // The GMT offset ensures that every visitor, regardless of their timezone, will see the schedule // that is appropriate for the site owner's local time. // Tip - for testing purposes you can put here //dy = 5; //hh = 9.25; // or whatever to check that the right show appears at that day/time. if (dy >=1 && dy <=5) { // days in Javascript are 0 Sunday - 6 Saturday if (hh >=0 && hh <3) {show = "Matt Knight at Night"} if (hh >=3 && hh <9) {show = "Non-Stop Music"} if (hh >=9 && hh <17) {show = "The Matt Knight Show"} if (hh >=17 && hh <18) {show = "Saving the 70's with Mike Walker"} if (hh >=18 && hh <20) {show = "Non-Stop Music"} if (hh >=20 && hh <21) {show = "Eighties at Eight with Rockin' Ron"} if (hh >=21 && hh <24) {show = "Matt Knight at Night"} } if (dy >= 2 && dy <=5) { if (hh >=0 && hh <3) {show = "Matt Knight at Night"} if (hh >=3 && hh <9) {show = "Non-Stop Music"} if (hh >=9 && hh <18) {show = "The Matt Knight Show"} if (hh >=18 && hh <19) {show = "Non-Stop Music"} if (hh >=19 && hh <20) {show = "Non-Stop Music"} if (hh >=20 && hh <21) {show = "Eighties at Eight with Rockin' Ron"} if (hh >=21 && hh <24) {show = "Hank and Jim Show"} } if (dy >= 3 && dy <=5) { if (hh >=0 && hh <3) {show = "Hank and Jim Show"} if (hh >=3 && hh <9) {show = "Non-Stop Music"} if (hh >=9 && hh <18) {show = "The Matt Knight Show"} if (hh >=18 && hh <19) {show = "Non-Stop Music"} if (hh >=19 && hh <20) {show = "Non-Stop Music"} if (hh >=20 && hh <21) {show = "Eighties at Eight with Rockin' Ron"} if (hh >=21 && hh <24) {show = "The Pete Sayek Show"} } if (dy >= 4 && dy <=5) { if (hh >=0 && hh <1) {show = "The Pete Sayek Show"} if (hh >=1 && hh <9) {show = "Non-Stop Music"} if (hh >=9 && hh <15) {show = "The Matt Knight Show"} if (hh >=15 && hh <18) {show = "Stafford's World - Mark Stafford"} if (hh >=18 && hh <19) {show = "Non-Stop Music"} if (hh >=19 && hh <20) {show = "Non-Stop Music"} if (hh >=20 && hh <21) {show = "Eighties at Eight with Rockin' Ron"} if (hh >=21 && hh <24) {show = "Matt Knight at Night"} } if (dy == 5) { if (hh >=0 && hh <3) {show = "Matt Knight at Night"} if (hh >=3 && hh <9) {show = "Non-Stop Music"} if (hh >=9 && hh <15) {show = "The Matt Knight Show"} if (hh >=15 && hh <18) {show = "Beachey Live from the U.K."} if (hh >=18 && hh <19) {show = "Catt Live from California"} if (hh >=19 && hh <20) {show = "Catt Live from California"} if (hh >=20 && hh <21) {show = "Catt Live from California"} if (hh >=21 && hh <23) {show = "Psychedelic Detached Garage - George Cannon"} if (hh >=23 && hh <24) {show = "Matt Knight at Night"} } if (dy == 6) { // Saturday Note the two = signs to mean equals if (hh >=0 && hh <10) {show = "Non-Stop Music"} if (hh >= 10 && hh <13) {show = "Stafford's World - Mark Stafford"} if (hh >=13 && hh <13.30) {show = "Cheeze Pleeze - Snarfdude and Dafodil"} if (hh >=13.30 && hh <20) {show = "Non-Stop Music"} if (hh >=20 && hh <23) {show = "Flashback with Matt Knight"} if (hh >=23 && hh <24) {show = "Imagination Theater"} } //End of Saturday Shows if (dy == 0) { //Sunday Shows if (hh >= 0 && hh <10) {show = "Non-Stop Music"} if (hh >=10 && hh <11) {show = "Motown Memories with Tom Fallon"} if (hh >=11 && hh <22) {show = "Non-Stop Music"} if (hh >=22 && hh <23) {show = "Imagination Theater"} if (hh >=23 && hh <24) {show = "Non-Stop Music"} } // End of Sunday Shows var a = "" + show + " \u00A0 \u00A0 \u00A0 \u00A0 "; // spaces must be separted by Unicode spaces to prevent collapse document.getElementById("dj").innerHTML = a; setTimeout("display()", 60000); // update every 60 seconds } </script> I'm still struggling for a solution here. I have a background image that auto-resizes based on browser window / screen resolution. I want my top header menu, which requires links, to act in the same way and be in roughly the same position/size based on browser window. Is this possible? In the sample below, the image is just part of the background image to give you an idea of the look I am trying to duplicate. Is there a Javascript out there that will help me or will I be stuck having to rework my design? http://www.uberbotjones.com/sanny/test.html This site is really driving me crazy. Hello all, Essentially what I am trying to get without much success on the issue is this: I want an icon in my template that, when you click on that certain icon (image), a drop down menu appears. You know when you click the file option in your browser's toolbar, and a drop down menu appears? It can be just like that, but instead of save as and open, links will be there to places within our intranet opened in a new window. This has to work for IEX 7+ because that's all our company decides to use. I tried to submit a chang erequest for them to move to a better CSS/Javascript supportive browser such as Opera, Firefox, Google Chrome... but they're way too fixed on IEX for some odd reason. I am obliged for any help on this. *edit* colors dont matter. It can be the default colors used in a basic drop down menu. I figure javascript would have more options though. I have gotten my script to do exactly what I want it to do with one exception. I have some thumbnail images that people can mouse over and the actual image is 100px by 75px. That is what I use for my thumbnail and they reside in www.website.com/images/thumbs/image1.jpg. I have the large version of the image that resides in www.website.com/images/image1.jpg. Its actual size is 640px by 480. When I mouse over my thumbnail, I don't want the thumbnail to appear for the larger image, I want the large image to appear instead? Let me know if you need ellaboration. Any help would be great! Thank you. Javascript Code: <script language="JavaScript"> function Change_Big_One(thumb){ document.getElementById('BigOne').src=thumb.src.replace("_th","") } </script> HTML THUMBNAIL Code: <div><img src="https://www.website.com/images/thumbs/image1.jpg" class="thumb" onMouseOver="Change_Big_One(this)"></div> HTML LARGER IMAGE Code: <div><img src="" id="BigOne"></div> |