Introduction
In this article I'm going to cover another important aspect of Windows 8 Metro UI and that is full screen notifications or alerts. Have you noticed it? The strip comes in the middle of your screen when an error happens in the window. We will create the same for our website. So let's start! (From now onwards I'll be using notification, full screen notification and alert box interchangeably. They all refer to full screen notification.)
Analyzing Windows 8 alert box
Whenever any error or serious action occurs in the OS or an app that requires user interference then we get this full screen alert notification. It is different from toast notifications that comes on the right side of the window. Some points about full screen notifications are:
- Some buttons are required on that notification to which the user can respond.
- The notification is full width but not full height.
- The notification should be at the top of the screen.
- The background is faded when the notification occurs.
- The background becomes active again on the close of the notification.
Logic for full screen notifications
- We need to fade our entire website when notification occurs.
- We need to bring in our notification on top of the site.
- The user should not be allowed to interact with the website until a notification is closed.
- Animation can be done using the fading effect of jQuery.
- The base of the notification can be created using a "div" tag.
- To avoid website interaction while the notification is overlayed on the website something can be added.
Let's now start coding this alert scheme.
Coding the Windows 8 full screen notification
HTML
-
<divid="overlay"></div>
-
<divid="alertBox">
-
<divid="btnctr">
-
<inputtype="button"id="btn1"value="OK"/>
-
<inputtype="button"id="btn2"value="CANCEL"/>
-
</div>
-
</div>
Div with id="overlay" represents an overlay div that will cover the entire website.
Div with id="alertBox" represents the full screen notification.
Div with id="btnctr" inside "alertBox" div is a container for the buttons of the notification.
CSS
-
body{
-
margin:0px;
-
}
-
#overlay{
-
background-image:url("http://www.hdwallpapers.in/walls/windows_8_official-wide.jpg");
-
background-size:contain;
-
}
-
-
#alertBox{
-
display:none;
-
background-color:#008a00;
-
width:100%;
-
height:30%;
-
top:40%;
-
position:absolute;
-
overflow: hidden;
-
}
-
-
#btnctr{
-
width: 305px;
-
overflow: hidden;
-
margin:140px 0px 0px 500px;
-
}
-
-
#btn1{
-
width:100px;
-
height:35px;
-
margin-right:100px;
-
}
-
#btn2{
-
width:100px;
-
height:35px;
-
}
Line numbers 5-6 sets the background image of the overlay and its attachment type.
Line numbers 10-16 are responsible for the notification design.
Line number 10 hides the notification initially. We will change this property from jQuery.
Line numbers 20-22 design the button container inside the notification.
Line numbers 26-28 and 31-32 design the buttons of the notification.
jQuery
-
$(document).ready(function(){
-
-
//Initilization
-
-
$("#overlay").css("width",$(window).width()+"px");
-
$("#overlay").css("height",$(window).height()+"px");
-
$("#alertBox").css("width",$(window).width()+"px");
-
-
//Activate
-
-
$("#overlay").click(function(){
-
$("#overlay").fadeTo(500,0.5);
-
$("#alertBox").fadeIn(500);
-
});
-
$("#btn1").click(function(){
-
$("#overlay").fadeTo(500,1);
-
$("#alertBox").fadeOut(500);
-
});
-
-
});
Line numbers 5, 6 and 7 initialize the size of the overlay and the notification as per the user screen.
Line number 11 triggers the notification whenever a click on the overlay is done. In practice this must be triggered by a button or some event on website data or from a user action.
Line number 12 fades the current active app (let it be an overlay) to 0.5 opacity in 500 milliseconds using the "fadeTo" function.
Line number 13 brings the notification on top of the website using a fade effect.
From now onwards the user can proceed ahead only by giving a response to the notification.
Line number 15 binds a click event with notification button 1 ("OK").
On the click of the "ok" button, line number 16 activates the Desktop and line number 17 hides the alert box.
In the preceding example I don't have an explicit Desktop so I treated the overlay as the Desktop but the code can be adjusted to accommodate this change in practical situation.
Output
LIVE OUTPUT
Summary
That's all for this article. If you have any suggestion regarding it's improvement then do share with me your comments. In the case of any doubt feel free to ask in the comments. Thank you for reading this article.