Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery mobile finding image height

Posted on 2013-01-30
4
Medium Priority
?
258 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 1500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Recently, we decided that in order to stay competitive in today's IT world, we were going to have to develop and deploy a mobile app for our users and do it quickly. We felt that we were already behind the curve. Users of technology today are mov…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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)

927 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