Solved

Jquery mobile finding image height

Posted on 2013-01-30
4
240 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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

Suggested Solutions

Title # Comments Views Activity
Embedding Tags in a restricted UI 6 28
Cross platform mobile development? 9 81
pass foreach data in php into jquery ajax 10 45
Jquery Bold 3 specific words in a paragraph 5 24
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

761 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