My page has bugs when viewed vertically, in addition it is best viewed horizontally.
Can you force a page to always open horizontally on mobile devices? And stay horizontal.
My page has bugs when viewed vertically, in addition it is best viewed horizontally.
Can you force a page to always open horizontally on mobile devices? And stay horizontal.
Do you want to disable the feature of the mobile device that redirects the view according to the position of the device? This is not possible.
What you can do is adapt your layout so that it appears "buggy" in an upright position.
You can determine a minimum width using CSS:
#conteudo {
min-width: 640px;
}
You can use media queries , a CSS feature to apply certain rules according to viewer characteristics, making design responsive in> ".
It is difficult to help more without seeing some image or code (preferably both).
Another crazy thing you can do is to use JavaScript to check if it's vertical (height> width), and if so, apply a CSS class to rotate the screen by 90 degrees. This way, the user will be "forced" to keep the device horizontal to see the site "standing up."
CSS class:
.virado {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}
JavaScript (with jQuery):
$(window).bind('resize', function() {
if (screen.height > screen.width) {
$('body').addClass('virado');
} else {
$('body').removeClass('virado');
}
});
An addition to J. Bruni's solution, which is certain is that a problem that always occurs with listeners in resize is that it can be fired many times per second and this may hang the screen in certain browsers, desktop.
In cases like this, it's interesting to use Debounced Resize()
that is described in link
// Plugin. Precisa ser adicionado apenas uma vez
(function($,sr){
// debouncing function from John Hann
// http://unscriptable.com/index.php/2009/03/20/debouncing-javascript-methods/
var debounce = function (func, threshold, execAsap) {
var timeout;
return function debounced () {
var obj = this, args = arguments;
function delayed () {
if (!execAsap)
func.apply(obj, args);
timeout = null;
};
if (timeout)
clearTimeout(timeout);
else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100);
};
}
// smartresize
jQuery.fn[sr] = function(fn){ return fn ? this.bind('resize', debounce(fn)) : this.trigger(sr); };
})(jQuery,'smartresize');
// Uso do plugin smartresize com a solução de J. Bruni
$(window).smartresize(function(){
if (screen.height > screen.width) {
$('body').addClass('virado');
} else {
$('body').removeClass('virado');
}
});
The CSS code stays the same
.virado {
-webkit-transform: rotate(90deg);
-moz-transform: rotate(90deg);
-o-transform: rotate(90deg);
transform: rotate(90deg);
}