Solved

Jquery mobile finding image height

Posted on 2013-01-30
4
207 Views
Last Modified: 2013-08-25
Hello experts,

the below script does not work.
what i am trying to do is to get the first image height so i can set the image container div height. all the images having the same height and width but because i resize it to 80% i need to know the height so i can set the container.

$(document).on('pageinit', function() {
	var houseContainerHeight = $('#img01').height();
	alert (houseContainerHeight);
		
	$('#img02, #img03').hide();
	
	$('#img01Btn').click (function() {
		$('#house-container img').hide();
		$('#img01').show(500);		
	});
	$('#img02Btn').click (function() {
		$('#house-container img').hide();
		$('#img02').show(500);		
	});
	$('#img03Btn').click (function() {
		$('#house-container img').hide();
		$('#img03').show(500);		
	});	
});

<div id="house-container" align="center" style="margin:auto; display:block; overflow:hidden'">
<img id="img01" src="images/ansichten/front.jpg" alt="" style="width:80%; ">
<img id="img02" src="images/ansichten/back.jpg" alt="" style="width:80%;">
<img id="img03" src="images/ansichten/garden.jpg" alt="" style="width:80%;">
</div>

Open in new window

0
Comment
Question by:Refael
  • 3
4 Comments
 
LVL 17

Accepted Solution

by:
sonawanekiran earned 500 total points
Comment Utility
Do like this...

$(document).on("pageshow", function() {
	var houseContainerHeight = $('#img01').height();
	alert (houseContainerHeight);
		
	$('#img02, #img03').hide();
	
	$('#img01Btn').click (function() {
		$('#house-container img').hide();
		$('#img01').show(500);		
	});
	$('#img02Btn').click (function() {
		$('#house-container img').hide();
		$('#img02').show(500);		
	});
	$('#img03Btn').click (function() {
		$('#house-container img').hide();
		$('#img03').show(500);		
	});	
});

Open in new window

0
 

Author Comment

by:Refael
Comment Utility
Hi sonawanekiran,

i am still getting "0" in the alert. for some reason i do not understand why!?
the script in currently inside the page at the bottom before the closing of the body and the html maybe that's the reason? should it be placed somewhere else?
0
 

Author Comment

by:Refael
Comment Utility
Hi sonawanekiran,

this is strange it works on my mobile when testing but not locally in the browser.
that's good it works. my question is when i rotate the screen can it re-calculate the image with and height?
0
 

Author Closing Comment

by:Refael
Comment Utility
Was right to the point! Thank you.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

What is a Lightbox? A Lightbox is the effect you see when you click, for example, an image and the screen fades out and up pops the same image but in its full size dimensions. There are lots of Lightbox effects for jQuery. Problem is they are a…
There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now