how to set 'div' element full of screen(width), when iphone change directions, it is also full screen(width) - iphone

And set the 'height' 1/2 of full screen.
This is my code:
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" manifest="/m?manifest=1">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no, width=device-width">
</head>
<body >
<div></div>
<style type="text/css">
div{
background:red;
}
</style>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
</script>
</body>
</html>

I would do it with a combination of css and javascript (using jquery).
for the javascript
updateOrientation : function() {
var orientation = window.orientation;
switch (orientation) {
// If we're horizontal
case 90:
case -90:
// Set orient to landscape
$(body).addClass("landscape");
break;
// If we're vertical
default:
// Set orient to portrait
$(body).addClass("portrait");
break;
}
}
for the css:
body{
height: 240px;
}
/* Reposition on orientation change */
body.landscape{
height: 160px;
}
This is just a basic outline, adjust it as you see fit

Related

Mapbox: Indian GPS co-ordinates show wrong place on map

I am trying to use the JS version of mapbox in my web application. BUt when changing the example lat-long to delhi's latlong its showing wrong location.
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.54.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
mapboxgl.accessToken = 'pk.eyJ1Ijoid2ViZXhwZXJ0c3VqZWV0IiwiYSI6ImNqdmh4MXM0dDAwMWs0NXFyNHkxc2o1eGwifQ.jgbBoS14uvv8i_lMrCQF5A';
var map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/mapbox/streets-v11', // stylesheet location
center: [28.6466773,76.813073], // starting position [lng, lat]
zoom: 9 // starting zoom
});
</script>
</body>
</html>
As High Performance Mark mentioned, MapBox uses swapped co-ordinates that means they are not using:
[lat, lng]
they are using
[lng, lat]
Try to change it and then try again.

Mapbox : Can't load features (markers) by map_id

When i try to load markers from my map i get this error message:
{"message":"Markers do not exist"}
This is my code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>BoxMap</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v3.0.1/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
</style>
</head>
<body>
<div id='map'></div>
<script>
L.mapbox.accessToken = 'this_is_my_token';
var map = L.mapbox.map('map')
.setView([40.447, -5.625], 2);
L.mapbox.styleLayer('mapbox://styles/this_is_my_style').addTo(map);
L.mapbox.featureLayer().loadID('this_is_my_map_id').addTo(map);
</script>
</body>
</html>
PS: when i try to put a map_id from the given examples on mapbox website, it works! example: examples.map-h61e8o8e
Thanks

jQuery - slideToggle to select and deselect button

I have a jsfiddle here - http://jsfiddle.net/eYV4n/
Really simple navigation and a hidden div block beneath it.
When you click the second link in the nav the div block slides down with slideToggle.
When the div block slides down I would like the button clicked to be selected.
I can do this when it's clicked by changing the background color.
Is it possible to deselect the link (change it's color back) when the div block slides again.
jquery.hover() handler hover-in and hover-out. Is it possible to do the same thing with slideToggle.
<!DOCTYPE html>
<html>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="robots" content="">
<title>Title of the document</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
*{
margin:0;
padding:0;
}
body{
background:#eee;
}
#wrap{
background:#fff;
max-width:800px;
margin:0 auto;
height:1000px;
}
ul{
list-style:none;
overflow:auto;
}
ul li{
display:inline;
}
ul li a {
float:left;
display:block;
color:#222;
padding:10px;
margin:0 5px 0 0;
}
#block{
width:100%;
margin:0 auto;
height:200px;
background:red;
display:none;
}
</style>
</head>
<body>
<div id="wrap">
<nav>
<ul>
<li>One</li>
<li>Two ↓</li>
<li>Three</li>
<li>Four</li>
</ul>
</nav>
<div id="block">
</div>
</div><!-- #wrap -->
<script>
$('#btn').click(function(e){
e.preventDefault();
$('#block').slideToggle('2000')
$('#btn').css('background','red');
})
</script>
</body>
</html>
A better solution is to toggle a class that in turn changes the background. You should make it a best practice to never style elements with Javascript, you should use CSS for that. Adding/removing classes is fine though. This will make the code much easier to maintain in the long run, and it's also more semantic since you're using classes and not inline styling.
Try this:
$('#btn').click(function(e){
e.preventDefault();
$('#block').slideToggle('2000')
$('#btn').toggleClass('active');
})
Then in your CSS.
.active { background: red; }
Edit: Jsfiddle here.

ms filter gradient and background image

Is there any way (other than using another element) to get a background image to sit on top of a gradient in IE8 and IE9? In the following example the gradient always overrides the background image. Thanks.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ms filter gradient and background image</title>
<style type="text/css">
div {
width:500px;
height:500px;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=red, endColorstr=blue)";
background:url('my-image.gif') no-repeat;
}
</style>
</head>
<body>
<div></div>
</body>
</html>

Weird behaviour when rotating iPhone for TDs with colspan

This is about displaying a simple HTML page in iPhone's browser, with rotation.
Setup: two identical tables but one of them has a (CSS) width of 69% while the other is at 100%.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=UTF-8" />
<meta name="HandheldFriendly" content="true" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable = yes" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>Test</title>
<style>
table
{
border-collapse: collapse;
}
th
{
font-weight: normal;
border: 1px solid red;
}
td
{
border: 1px solid green;
}
#t1
{
width: 69%;
}
#t2
{
width: 100%;
}
</style>
</head>
<body>
<table id="t1">
<tr><th colspan="2">TH COLSPAN 2</th></tr>
<tr><td colspan="2">TD COLSPAN 2</td></tr>
<tr><td>CELL 1</td><td>CELL 2</td></tr>
</table>
<hr />
<table id="t2">
<tr><th colspan="2">TH COLSPAN 2</th></tr>
<tr><td colspan="2">TD COLSPAN 2</td></tr>
<tr><td>CELL 1</td><td>CELL 2</td></tr>
</table>
</body>
</html>
Behaviour: although the two tables are displayed with the same font size in the default orientation (portrait), when rotating the device the full width table displays TDs/THs having a COLSPAN=2 in a bigger font size (screenshots are taken from iPhone):
This seems to be a bug in Safari but, nonetheless, I have to get around it.
Any idea about a decent workaround?
Thanks.
This is because sometimes Safari webview Zooms text automatically when it thinks its a good idea.
To disable this behavior add this to your body CSS Style:
-webkit-text-size-adjust:none;