Can a website force a device rotation lock? - rotation

I'm currently working on a website that is relatively equal for all devices; desktop & mobile. I'm working with % as I think that is the best option.
It's based on portrait mode. If you change the device to landscape, the whole website looks like a fat midget.
So I'm wondering: Is there a possibility to lock a website, displaying it in portrait all the time?
And by that, I mean: Device rotation locked. Not that when going to landscape, the website returns back to portrait, while in landscape. (which I already saw some code on StackOverflow.)
Check my site at: http://prototyping.iscs.nl/mobiel.html
for reference :)
Thanks in advance

In an update to an old ('12) question, I think this can help a lot of people!
I haven't figured out a true way of locking the device rotation, but came up with a perfect alternative, which I've seen a few people do too.
Option A. One simple alert
By use of a simple jQuery script, you can detect the orientation of your device.
if(window.innerHeight > window.innerWidth){
alert("Please use Landscape!");
}
Well, a simple alert is easy, but the notification can be quite nicer!
Option B. One nice image notification
(update as of 04-2018: (as I just saw my post again, I thought of something easier..) use media queries. Pretty much the same as below, but instead of using Javascript, use css, hide the element by default and show it when the orientation is landscape → #media (orientation: landscape) {...})
Simply add an fixed element to your page that is shown when the orientation has changed.
HTML
<div class="turnDeviceNotification"></div>
CSS
.turnDeviceNotification {
position:fixed;
top: 0;
left:0;
height:100%;
width:100%;
display: none;
}
You can update this element with text, or simply connect it to a background-image by
.turnDeviceNotification {
background-image:url('../images/turnDevice.jpg');
background-size:cover;
}
Simply add a nice background to your images folder, such as the one below.
Noticed the object has an display: none ? That's because else it'd be shown even in portrait mode. Now, all you need to do is to use the script below, so the object is shown only in landscape mode.
jQuery(window).bind('orientationchange', function(e) {
switch ( window.orientation ) {
case 0:
$('.turnDeviceNotification').css('display', 'none');
// The device is in portrait mode now
break;
case 180:
$('.turnDeviceNotification').css('display', 'none');
// The device is in portrait mode now
break;
case 90:
// The device is in landscape now
$('.turnDeviceNotification').css('display', 'block');
break;
case -90:
// The device is in landscape now
$('.turnDeviceNotification').css('display', 'block');
break;
}
});
This will show the notification only when the device orientation has changed to landscape.

Not possible. Lock rotation is a device setting: http://support.apple.com/kb/HT4085
When not locked by device, the browser will rotate and since your content is inside the browser, the content will rotate too.
Maybe the viewport will help in solving your problem: < meta name="viewport" content="width = device-width"/>". I see you're missing that meta tag.

I don't think is possible but there are couple of ways to work around
js way: window.DeviceOrientationEvent
css way
#media (orientation: landscape) {
body { background-color: black; }
}

#media screen and (min-width: 320px) and (max-width: 767px) and (orientation: landscape) {
html {
transform: rotate(-90deg);
transform-origin: left top;
width: 100vh;
overflow-x: hidden;
position: absolute;
top: 100%;
left: 0;
}
}
Source : https://css-tricks.com/snippets/css/orientation-lock/

Not possible as of now. But the other way around would be,
Using CSS,
Media query helped work properly for a landscape view.
min-aspect-ratio: 13/9 is very important as if you don't specify this, for some mobile devices, if you focus on a form field, the keyboard is opened, which basically changed the viewport's height which basically triggers the landscape media query. Hence min-aspect-ratio is very important for landscape media query.
#media only screen and (min-width: 320px) and (max-width: 1023px) and (min-aspect-ratio: 13/9) and (orientation: landscape) {
// Landscape view properties
}
Using JavaScript, we can use screen.availHeight as screen height doesn't change when keyboard displays. Also have to add more checks to allow Desktop view for following.
var currentOrientation = function() {
if(screen.availHeight < screen.availWidth){
// Landscape view
} else {
// Portrait view
}
}
// Set orientation on initiliasation
currentOrientation();
// Reset orientation each time window is resized. Keyboard opening, or change in orientation triggers this.
window.addEventListener('resize', currentOrientation);

Related

YouTube embed showinfo has been deprecated

We are using a YouTube video on our website as a hero banner.
However few days ago it started showing it's title, watch later button and a share button. We were able to hide them using &showinfo=0 at the end if the URL.
I found out that showinfo has been deprecated and thus you can no longer hide the fact that it is a YouTube video showing there.
Is there any other parameter that might be able to do the same thing?
You cannot do it with CSS or JavaScript as it is an iframe.
Any ideas are much appreciated.
UPDATE:
Any layer or mask over the video doesn't help, as the info shows when the video is loading, or if you click outside the browser, the video will pause and the info shows.
Hiding the top ~60px works, but it is not a good solution for me.
Directly from show info
Note: This is a deprecation announcement for the showinfo parameter. In addition, the behavior for the rel parameter is changing. Titles, channel information, and related videos are an important part of YouTube’s core user experience, and these changes help to make the YouTube viewing experience consistent across different platforms.
The behavior for the rel parameter is changing on or after September 25, 2018. The effect of the change is that you will not be able to disable related videos. However, you will have the option of specifying that the related videos shown in the player should be from the same channel as the video that was just played.
It clearly states that this is something they consider to be part of the cor youtube experience. There is no suggestion of a workaround or a new parameter that you could send to archive the old results. They are removing it. If you tried to force it out using javascript and css i would almost suggest you are against the TOC which states your not allowed to change that display. People should know you are showing something from YouTube
If you need to hide the info, ideally go for Vimeo pro (which properly supports a no info embed),
Otherwise there is a simple workaround:
https://jsfiddle.net/10ov5hgw/1/
It cuts off the bottom & top 60px of the iframe, but via overflow rather than a gross looking black bar on top, so video still looks fullscreen the entire time (and barely any of the video is cutout if you force 720) ,
This hack supports having to support mobile views aswell, without heavily impacting the visible area of the video.
.video-container{
width:100vw;
height:100vh;
overflow:hidden;
position:relative;
}
.video-container iframe,{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
.video-container iframe, {
pointer-events: none;
}
.video-container iframe{
position: absolute;
top: -60px;
left: 0;
width: 100%;
height: calc(100% + 120px);
}
.video-foreground{
pointer-events:none;
}
<div class="video-container" >
<div class="video-foreground">
<iframe
src="https://www.youtube.com/embed/W0LHTWG-UmQ?controls=0&showinfo=0&rel=0&autoplay=1&loop=1&playlist=W0LHTWG-UmQ&mute=1"
frameBorder="0" allowFullScreen>
</iframe>
</div>
</div>
The solution I found aesthetically most pleasing is to lay a high res thumbnail over the video and hide it at hover. This also deals with the problem that the youtube preview is low res and looks cheap in my opinion.
Check it out here:
http://jsfiddle.net/d9D9E/1/
Had to write code in order to show the js fiddle :/
.video-thumbnail{
z-index:300;
position:absolute;
top:0;
left:0;
width:100%;
}
.video-thumbnail:hover{
display:none;
}
Not having 'rel=0' is irritating, but there is a work around. If you work with the IFrame API, (as opposed to embedding an iframe ex http://youtu.be/?videoIDxxx...) you can get the event for the stopping (completing) of the video, then cue up the video by ID into the player. See https://developers.google.com/youtube/iframe_api_reference#Playback_controls for reference to the basic player.
....
<div id="player1"></div>
<script type="text/javascript">
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player ;
function onYouTubeIframeAPIReady()
{
player = new YT.Player('player1',
{
videoId: 'YourVideoId',
events: {
'onStateChange': onPlayerStateChange
}
});
}; // onYOuTubeIframeAPIReady
function onPlayerStateChange(event)
{
// Alt approach //if( event.data == 0){ location.reload()}
if( event.data == 0)
{ player.cueVideoById({videoId:'YourVideoID',
suggestedQuality: 'hd720'})
};
}
</script>
I was looking at the same problem and the only solution I found is to set the video in autoplay and place a transparent layer over the youtube box.
The user would not be able to interact with the player, but it can be useful in some situation like banner.
Unfortunately the code doesn't seem to run correctly on stackoverflow I also add a jsfiddle: http://jsfiddle.net/z3dqpuy0/
.yt-cntainer {
position: relative;
}
.yt-mask {
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
<div class="yt-cntainer">
<iframe id="vid-player-1" src="https://www.youtube.com/embed/Bey4XXJAqS8?enablejsapi=1&rel=0&controls=0&showinfo=0&autoplay=1" frameborder="0"></iframe>
<div class="yt-mask"></div>
</div>
Well, I just noticed it as well. It sucks and ruins the aesthetics. So I just did a
header {
/* remove when YT got its brain back */
margin-top: -56px;
}
while hoping that they'll re-add showinfo=0 again.
What about this. Yeah this will zoom the video.
iframe {
transform:scale(1.4);
}
<div id="schnitt">
<iframe width="500" height="280" src="https://www.youtube.com/embed/rlR4PJn8b8I?controls=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</div>
<style>
#schnitt {
height:250px;
overflow:hidden;
}
iframe {
margin-top:-55px;
}

Using a CSS image sprite for hover effect without the scrolling animation

I'm using a sprite image to change the background on hover and click (the .keepImage class is for the click). It all works, but when the background picture changes it scrolls over to the correct position. Is there a way to do it without the scrolling motion?
JS:
<script>
$(document).ready(function(){
$("a.doing").click(function() {
$(this).siblings(".keepImage").removeClass("keepImage");
$(this).addClass("keepImage");
});
});
</script>
CSS:
a.doing {
width: 229px;
height: 202px;
margin-right: 8px;
background: url(http://localhost:8000/img/manifesto/spr_doing.png) 0 0;
}
a.doing:hover, a.doing.keepImage {
background: url(http://localhost:8000/img/manifesto/spr_doing.png) -229px 0;
}
I think, somewhere in your css you have the transition property specified. Usually when you have a transition property specified like this: "transition: all 500ms ease;", the background position will change with a scrolling effect. If you want to prevent this scrolling from happening, then you can either remove the transition property completely, or you can use transition only for the properties you want to animate like - border, color etc.. but not background. If you can somehow provide a link to your page, or give the html mark up and css, it will help. Thanks.

IE8 Transparent PNG problems in Nivo Slider using background-image for Prev and Next Buttons

I'm using the nivo slider on our site
It's working great on all devices except for IE8 on XP, which due to the infamous IE transparent png issue, I get black borders around the prev and next buttons on rollover. The prev and next buttons need to be transparent pngs as they have a drop-shadow and are placed on top of transitioning images.
The Arrows
The Problem IN IE8 XP
The HTML
<div class="nivo-directionNav">
<a class="nivo-prevNav" style="display: none;"></a>
<a class="nivo-nextNav" style="display: none;"></a>
</div>
The CSS
.nivo-directionNav a {
position:absolute;
z-index:9;
cursor:pointer;
}
/* the arrows are taken from a single sprite with a standard and active image
for prev and next with the background-position changed on rollover */
.nivo-prevNav, .nivo-nextNav {
width: 80px;
height: 100%;
}
.nivo-prevNav {
left:0px;
background: url("images/nivo_4_arrows.png") no-repeat 0 0;
}
.nivo-prevNav:hover {
background: url("images/nivo_4_arrows.png") no-repeat -80px 0;
}
I have tried to implement this javascript as a fix:
var i;
for (i in document.images) {
if (document.images[i].src) {
var imgSrc = document.images[i].src;
if (imgSrc.substr(imgSrc.length-4) === '.png' || imgSrc.substr(imgSrc.length-4) === '.PNG') {
document.images[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='" + imgSrc + "')";
}
}
}
...as well as this plugin found on a similar post on this forum but neither have proved successful.
Been wasting lots of time on this so I'd really appreciate anyone that can shed some light on a fix!
Try to insert the following lines into 'nivo-slider.css' (a style for no theme specified):
.nivo-slice
{
background: transparent;
-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF)" !important;/* IE8 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#00FFFFFF,endColorstr=#00FFFFFF) !important;/* IE6 & 7 */
zoom: 1;
}
It works for the slice effect, but put this for the other effects, however in my case this solution changes the fade effect into a simple changing pictures effect (without fading). Maybe it'll help you.
This javascript script will not work with images on backgrounds, only "img src"...
there are 2 ways to solve:
use "img src" and put "position:absolute" and positioning the image in the background.
OR
Make an if IE and instead of background-image use:
filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='crop',src='link-to-image');
keep using backgroung-image for other browsers..

Media Queries Flash Banner Q

Quick question: I have a flash banner which is 1000px wide. I'm wanting that when a user's screen (like a smartphone) is less than 1000px, a image is substituted. How can I accomplish that? Thank you!
Hide the flash banner and show display the image when width is less than 1000px using this code in css:
#media screen and (min-width:1000px) {
#flash_banner {display:block;}
#image {display:none;}
}
#media screen and (max-width:999px) {
#flash_banner {display:none;}
#image {display:block;}
}
Hope it works well for you.

Tablet landscape specific with media queries

I have a 'responsive' website but there are some links I only want on 'pc browsers' only and not on 'tablet landscape' becasue they link off to flash objects.
So far this is what I have done but it't not a 100% fix as some android tablets such as 'Lenovo think pad' which have a bigger screen.
I am using media queries to make my site responsive and this is what I'm currently using...
#media only screen
and (max-device-width : 1024px)
and (orientation:landscape)
{
header.Site
{
nav.Site > ul > li { line-height: 2 ; }
div.BidSessionCountdown,
a.LiveOnline { display: none; }
}
}
Is there any CSS fixes you can think of?
Thank you in advance
Tash :D
Using media queries isn't really the appropriate technique to detect if flash is supported or not. My suggestion would be to determine this using JavaScript, and assign a class to the body element such as "no-flash". Your JavaScript might look like this:
//Using jQuery here
if(typeof navigator.plugins['Shockwave Flash'] == 'undefined') {
$('body').addClass('no-flash');
}
Then, your CSS could be as follows:
body.no-flash a.LiveOnline {
display:none;
}
Note: The javascript code that checks the navigator plugin comes from Here.
When you are using the orientation:landscape, you have to consider whether the keyboard popup will change the display, once the width size is larger than the height size, the css will consider it as landscape.

Resources