Be a Supporter!

Determining an images actual height

  • 341 Views
  • 5 Replies
New Topic Respond to this Topic
Zef
Zef
  • Member since: Dec. 13, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Determining an images actual height 2010-04-29 10:39:44 Reply

I have this following code that enlarges an image when you click it. It works great BUT the height of each image I use will be different. I want all images to load to their natural height. What javascript could I use to call in the images original ACTUAL height into where it says height goes here?

<img src="example.jpg" height="440"  onclick="this.src='example.jpg';this.height=HEIGHT GOES HERE" ondblclick="example.jpg';this.height=440"/>

Thanks in advance!


/

BBS Signature
Jon-86
Jon-86
  • Member since: Jan. 30, 2007
  • Offline.
Forum Stats
Member
Level 14
Blank Slate
Response to Determining an images actual height 2010-04-29 11:27:55 Reply

Don't set the height attribute and it will load the full sized image by default...


PHP Main :: C++ Main :: Java Main :: Vorsprung durch Technik
irc.freenode.net #ngprogramming

BBS Signature
Zef
Zef
  • Member since: Dec. 13, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Determining an images actual height 2010-04-29 11:33:05 Reply

At 4/29/10 11:27 AM, Jon-86 wrote: Don't set the height attribute and it will load the full sized image by default...

I want it to load full size only when I click it though.


/

BBS Signature
GustTheASGuy
GustTheASGuy
  • Member since: Nov. 2, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Determining an images actual height 2010-04-29 13:02:24 Reply

http://krook.org/jsdom/Element.html

Remove the width/height attributes via JS when clicked and it will be resized back to default size.


BBS Signature
Zef
Zef
  • Member since: Dec. 13, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Determining an images actual height 2010-04-29 13:41:40 Reply

At 4/29/10 01:02 PM, GustTheASGuy wrote: http://krook.org/jsdom/Element.html

Remove the width/height attributes via JS when clicked and it will be resized back to default size.

OK that makes sense but my js is terrible. What do i take from the page you linked me to?


/

BBS Signature
CronoMan
CronoMan
  • Member since: Jul. 19, 2004
  • Offline.
Forum Stats
Member
Level 06
Blank Slate
Response to Determining an images actual height 2010-04-30 04:39:48 Reply

Sounds like a job for jQuery!
Use the functions to add and remove a class or attribute.. something like :

$(function()
{
    $(".zoomimage").click(function()
    {
        if($(this).hasClass("unzoomed"))
            $(this).removeClass("unzoomed");
        else
            $(this).addClass("unzoomed");
    });
});

where in the css-class unzoomed, you constrain the size (which you put on the image by default)

<style type="text/css">
.unzoomed
{
    height: 100px;
}
</style>

<img class="zoomimage unzoomed" src="goatse.jpg" />
<img class="zoomimage unzoomed" src="tubgirl.jpg" />

"no sound in ass"