Solved

Jquery mobile finding image height

Posted on 2013-01-30
4
227 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
ID: 38834785
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
ID: 38835319
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
ID: 38835418
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
ID: 39437552
Was right to the point! Thank you.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we will discuss all things related to StageFright bug, the most vulnerable bug of android devices.
Read about why website design really matters in today's demanding market.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

773 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