Showing posts with label HTML5. Show all posts
Showing posts with label HTML5. Show all posts

Friday, May 23, 2014

Stick Menu Code

Jquery Code:

<script type="text/javascript">
$(window).scroll(function () {
    var iCurScrollPos = $(this).scrollTop();
    if (iCurScrollPos > 130) {
        $('nav').css('position','fixed');
$('.sticky-logo').css('display','none');
    } else {
        $('nav').css('position','relative');
$('.sticky-logo').css('display','block');
    }
    //iScrollPos = iCurScrollPos;
});
</script>

=====================================


CSS Code:
nav {
background: url(images/menu_bg.png) 0 0 repeat-x;
z-index:99999;
top:0px;
left:0;
width:100%;
}
.menu {
display: inline-block;
min-width: 100%;
list-style:none;
border-top: 1px solid #ccc;
border-left: 1px solid #ccc;
border-bottom: 1px solid #ccc;
position: relative;
background-color:#666;
text-align: center;
z-index:99999999;
}

Thursday, February 21, 2013

Convert a Menu to a Dropdown for Small Screens

The Five Simple Steps website has a responsive design with a neat feature. When the browser window is narrow, the menu in the upper right converts from a regular row of links into a dropdown menu.

When you're on a small screen (iPhone shown here) and click the dropdown, you get an interface to select an option where each option is nice and big and easy to choose.

That sure makes it easier to pick a place to go than a tiny link. Yeah, it's two taps instead of one, but that's arguable since you'd probably have to zoom in to tap the right link otherwise.

The HTML

The HTML for these two menus is different. As far as I know, you can't style <select> and <option> elements to look and behave like <a>s or vice versa. So we need both. You could just put both in the markup. That's what Five Simple Steps does:
<nav> 

  <ul> 
    <li><a href="/" class="active">Home</a></li> 
    <li><a href="/collections/all">Books</a></li> 
    <li><a href="/blogs/five-simple-steps-blog">Blog</a></li> 
    <li><a href="/pages/about-us">About Us</a></li> 
    <li><a href="/pages/support">Support</a></li> 
  </ul> 
  
  <select> 
    <option value="" selected="selected">Select</option> 
    
    <option value="/">Home</option> 
    <option value="/collections/all">Books</option> 
    <option value="/blogs/five-simple-steps-blog">Blog</option> 
    <option value="/pages/about-us">About Us</option> 
    <option value="/pages/support">Support</option> 
  </select> 

</nav>
Let's go with that for now.

The CSS

By default we'll hide the select menu with display: none;. This is actually good for accessibility, as it will hide the redundant menu from screen readers.
nav select {
  display: none;
}
Then using media queries, we'll do the switcheroo at some specific width. You can determine that on your own (here's some standard breakpoints).
@media (max-width: 960px) {
  nav ul     { display: none; }
  nav select { display: inline-block; }
}

But now you gotta maintain two menus?

Well yeah, that's one concern. Maybe your menus are created dynamically and you can't control the output easily. Maybe you and hand crafting menus but want to make sure you don't accidentally get your menus out of sync. One way we can fight this is to dynamically create the dropdown menu from the original.
Using jQuery, we can do that with just a few lines of code:
// Create the dropdown base
$("<select />").appendTo("nav");

// Create default option "Go to..."
$("<option />", {
   "selected": "selected",
   "value"   : "",
   "text"    : "Go to..."
}).appendTo("nav select");

// Populate dropdown with menu items
$("nav a").each(function() {
 var el = $(this);
 $("<option />", {
     "value"   : el.attr("href"),
     "text"    : el.text()
 }).appendTo("nav select");
});
Then to make the dropdown menu actually work...
$("nav select").change(function() {
  window.location = $(this).find("option:selected").val();
});

But aren't dropdown menus kinda obtrusive?

Kinda. Most small screens these days are mobile and most mobile devices are JavaScript friendly, so not a huge concern. But, if you want to ensure this works with or without JavaScript I have an article about that.

Thursday, January 17, 2013

Responsive Doctype and Header Code

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<head>
  <!--[if lt IE 9]>
    <script type="text/javascript" src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
</head>
<body>
Content 
</body> 

Thursday, August 2, 2012

HTML5 Features


1.      New Doctype

( HTML )       <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
( HTML5 )    <!DOCTYPE html>

2.      The Figure Element

( HTML )       <img src="image/image.jpg" alt="image" title=” image” />
        <p>Image of Mars. </p>
( HTML5 )
<figure>
    <img src="image/image.jpg" alt="image" title=”image” />
    <figcaption>  
        <p>This is an image of something interesting.</p>  
    </figcaption>  
</figure>  

3.      No More Types for Scripts and Links

( HTML )     <link rel="stylesheet" href="css/ stylesheet.css" type="text/css" />  
      <script src="path/to/script.js" type="text/javascript"></script>
( HTML5 )  <link rel="stylesheet" href="css/stylesheet.css" />
     <script src="path/to/script.js"></script>  
  

4.      To Quote or Not to Quote.

( HTML )     <p class=”myclass” id=”someId”> Welcome.</p>
( HTML5 )  <p class=myclass id=someId> Welcome.</p>
 

5. Email Inputs

( HTML5 )
                 <!DOCTYPE html>  
                       <html lang="en">  
                            <head>  
                                  <meta charset="utf-8">  
                                      <title>untitled</title>  
                            </head>  
                            <body>  
                                  <form action="" method="get">  
                                      <label for="email">Email:</label>  
                                          <input id="email" name="email" type="email" />
                                          <button type="submit"> Submit Form </button>  
                                   </form>  
                            </body>  
                       </html>

6.  The Semantic Header and Footer

( HTML )      <div id="header">    ...  </div>    
                       <div id="footer">       ...  </div>  
( HTML5 )    <header>       ...      </header>  
                        <footer>          ...      </footer>

7.Audio Support

( HTML5 ) HTML5 now offers the <audio> element.
                        <audio autoplay="autoplay" controls="controls">  
                             <source src="file.ogg" />  
                             <source src="file.mp3" />  
                             <a href="file.mp3">Download this file.</a>  
                        </audio>  

8. Video Support

( HTML5 ) HTML5 now offers the <vidio> element.
                        <video controls preload>  
                             <source src="cohagenPhoneCall.ogv" type="video/ogg; codecs='vorbis, theora'" />  
                             <source src="filename.mp4" type="video/mp4; 'codecs='avc1.42E01E, mp4a.40.2'" />  
                             <p>Your browser is old.<a href="cohagenPhoneCall.mp4">Download this video instead.</a></p>  
                        </video>  

Thursday, March 8, 2012

Sexy New Semantics

http://coding.smashingmagazine.com/2011/11/18/html5-semantics/

We all know about video and audio. And canvas is particularly popular at the moment because it allows for 3-D graphics using webGL, so game designers can port their products to the Web. Like good ol’ img, these semantics are embedded content, because they drag in content from another source — either a file, a data URI or JavaScript.
Unlike img, however, they have opening and closing tags, allowing for fallbacks. Therefore, browsers that don’t support the new semantics can be fed some content: an image could be the fallback for a canvas, for example, or a Flash movie could be the fallback for video, a technique called “video for everybody.”
The source and track elements are empty elements (with no closing tags) that are children of video or audio.
The source element gets past the codec Tower of Babel that we have. Each element points to a different source file (WebM, MP4, Ogg Theora), and the browser will play the first one it knows how to deal with:
<audio controls> <source src=bieber.ogg type=audio/ogg> <source src=bieber.mp3 type=audio/mp3> <!-- fallback content: --> Download <a href=bieber.ogg>Ogg</a> or <a href=bieber.mp3>MP3</a> formats. </audio> 
In this example, Opera, Firefox and Chrome will download the Ogg version of Master Bieber’s latest toe-tappin’ masterpiece, while Safari and IE will grab the MP3 version. Chrome can play both Ogg and MP3, but browsers will download the first source file that they understand. The fallback content between the opening and closing tags is a link to download the content to the desktop and play it via a separate media player, and it is only shown in browsers that can’t play native multimedia.
For video, you could use an embedded Flash movie hosted on YouTube:
<video controls> <source src=best-video-ever.webm type=video/webm> <source src=best-video-ever.mp4 type=video/mp4> <!-- fallback content: --> <iframe width="480" height="360" src="http://www.youtube.com/embed/xzMUyqmaqcw?rel=0" frameborder="0" allowfullscreen> </iframe> </video> 
This way, users of older browsers, such as IE 6-8, will see a YouTube movie (as long as they have the Flash Player), so they will at least be able to see the video, while users with modern browsers will get the full native-video experience. Everyone gets the content, then, which is what your website is there for, after all.
The track element is a newer addition to the HTML5 family and is being implemented by Opera, Chrome and IE at the moment. It points to a subtitle file that contains text and timing information. When implemented, it synchronizes captions with the media file to enable on-demand subtitling and captioning; useful not only for viewers who are hard of hearing, but also for those who do not speak the language used in the audio or video file.

Monday, November 28, 2011

DOCTYPE - Definition and Usage

The doctype declaration should be the very first thing in an HTML document, before the tag.

The doctype declaration is not an HTML tag; it is an instruction to the web browser about what version of the markup language the page is written in.

The doctype declaration refers to a Document Type Definition (DTD). The DTD specifies the rules for the markup language, so that the browsers render the content correctly.

Tuesday, March 29, 2011

The Current State of HTML5 Forms

HTML5 has many new features intended to make the process of creating websites easier and to improve people’s experience in using those websites. Among the features are many enhancements to Web forms. Because HTML5 is fairly new and not all of its features have been worked out yet, not every browser supports HTML5 features the same way.
The Current State of HTML5 Forms
On Wufoo’s HTML5 Forms website, you can explore all of the new features to learn which browsers support which features and to what extent. The list of browsers includes various versions of Firefox, Safari, Chrome, Opera and Internet Explorer. Unfortunately, IE9 is far from wide HTML5 support in terms of HTML5 Forms. (tb)