<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dev.enekoalonso.com &#187; orientation</title>
	<atom:link href="http://dev.enekoalonso.com/tag/orientation/feed/" rel="self" type="application/rss+xml" />
	<link>http://dev.enekoalonso.com</link>
	<description>having fun with code</description>
	<lastBuildDate>Wed, 12 Oct 2011 21:40:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Detecting iPhone&#8217;s orientation</title>
		<link>http://dev.enekoalonso.com/2008/12/02/detecting-iphones-orientation/</link>
		<comments>http://dev.enekoalonso.com/2008/12/02/detecting-iphones-orientation/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 16:59:23 +0000</pubDate>
		<dc:creator>Eneko Alonso</dc:creator>
				<category><![CDATA[uncategorized]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[landscape]]></category>
		<category><![CDATA[orientation]]></category>
		<category><![CDATA[portrait]]></category>

		<guid isPermaLink="false">http://dev.enekoalonso.com/?p=70</guid>
		<description><![CDATA[Detecting the iPhone&#8217;s orientation on a website is very easy: the only thing needed is a little bit of Javascript to listen to the onorientationchange event: window.onorientationchange = function&#40;&#41; &#123; &#160; if &#40;window.orientation&#41; &#160; &#160; document.body.setAttribute&#40;&#39;class&#39;, &#39;landscape&#39;&#41;; &#160; else &#160; &#160; document.body.setAttribute&#40;&#39;class&#39;, &#39;portrait&#39;&#41;; &#125; window.onload = function&#40;&#41; &#123; &#160; window.onorientationchange&#40;&#41;; &#125; The window.orientation variable can [...]]]></description>
			<content:encoded><![CDATA[<p>Detecting the iPhone&#8217;s orientation on a website is very easy: the only thing needed is a little bit of Javascript to listen to the <code>onorientationchange</code> event: </p>
<div class="geshi no javascript">
<ol>
<li class="li1">
<div class="de1">window.<span class="me1">onorientationchange</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>window.<span class="me1">orientation</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; document.<span class="me1">body</span>.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">&#39;class&#39;</span>, <span class="st0">&#39;landscape&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; document.<span class="me1">body</span>.<span class="me1">setAttribute</span><span class="br0">&#40;</span><span class="st0">&#39;class&#39;</span>, <span class="st0">&#39;portrait&#39;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">window.<span class="kw3">onload</span> = <span class="kw2">function</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; window.<span class="me1">onorientationchange</span><span class="br0">&#40;</span><span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
<p>The <code>window.orientation</code> variable can have three different values: 0, 90 and -90. In most cases we wont mind if its 90 or -90, since both are landscape, so I have ignored this on the code above. Adding a CSS class to the body is the cleanest way to handle iPhone&#8217;s orientation. Now it&#8217;s up to you to set up the CSS for both layouts.</p>
<p>The resolution of the visible screen (viewport) changes drastically from portrait to layout, so be aware of this:</p>
<ul>
<li>Portrait visible screen: 320 x 356 px</li>
<li>Landscape visible screen: 480 x 196 px</li>
</ul>
<p>Source: <a href="https://developer.apple.com/webapps/docs/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/chapter_7_section_9.html">Web Apps Reference Library &#8211; Handling Orientation Events</a> (needs registration)</p>
<h3  class="related_post_title">Related Posts:</h3><ul class="related_post"><li>June 14, 2011 -- <a href="http://dev.enekoalonso.com/2011/06/14/titanium-studio-and-titanium-mobile-1-7/" title="Titanium Studio and Titanium Mobile 1.7">Titanium Studio and Titanium Mobile 1.7</a> (0)</li><li>September 17, 2010 -- <a href="http://dev.enekoalonso.com/2010/09/17/mootools-core-for-server-and-mobile-development/" title="MooTools Core for Server and Mobile Development">MooTools Core for Server and Mobile Development</a> (1)</li><li>August 22, 2010 -- <a href="http://dev.enekoalonso.com/2010/08/22/list-of-iphone-ipsw-firmware-files/" title="List of iPhone ipsw firmware files (yes, downgrading from iOS 4.0.1 to 3.1.3)">List of iPhone ipsw firmware files (yes, downgrading from iOS 4.0.1 to 3.1.3)</a> (2)</li><li>August 18, 2010 -- <a href="http://dev.enekoalonso.com/2010/08/18/titanium-developer-love-and-hate-part-ii/" title="Titanium Developer: love and hate (Part II)">Titanium Developer: love and hate (Part II)</a> (0)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://dev.enekoalonso.com/2008/12/02/detecting-iphones-orientation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

