Thursday 22 March 2012

Custom select dropdown with CSS and JS

Dropdowns have been a major pain in the backside in the past when it comes to styling of them, the default look doesn't always suite your website theme.


Customization is very limited, but it's not very difficult to change the style of the dropdown with CSS and javascript.


Lets turn this:






Into this:






Step 1
The HTML - This is simple, basically we have a div which holds the select element, it also holds the span element:


<div class="selection">
    <select class="selectbox" onchange="changeValue(this.value);">
        <option>test select</option>
        <option>test select 2</option>
        <option>test select 3</option>
        <option>test select 4</option>
        <option>test select 5</option>
    </select>
    <span id="selector">test select</span>
</div>


Step 2
The CSS - this tells the select element to become invisible, and tells the span what to look like and to sit below the selectbox.


<style>
.selection { position:relative; }

.selectbox,#selector {
 position:absolute;
 top:0;
 left:0;
 font-family:Arial, Helvetica, sans-serif;
 font-size:15px;
}

.selectbox {
 width:220px;
 padding:5px;
 height:30px;
 opacity:0;
 z-index:5;
}

#selector {
 background-image:url(dropdown.jpg);
 background-repeat:no-repeat;
 padding:5px 43px 5px 10px;
 overflow:hidden;
 width:162px;
 height:20px;
 color:#fff;
}
</style>


Perfect, as you can see from the CSS, the span with the id of #selector uses a background image called dropdown.jpg - this gives the coloured background and the arrow, you can make your own one. - this image is 215x30px if you change the size of it make sure you adjust the CSS accordingly, basically fiddle around with the #selector width and padding. You may also need to change the .selectbox width and padding if you experience difficulty clicking the dropdown once you've changed the size.


Step 3
The Javascript - this is just to update the span with the selected dropdown option.


You can do this with the jQuery library (if you already use it on your website), or using built in javascript, both work fine:


jQuery


<script>
function changeValue(val)
{
 $('#selector').html(val);
}
</script>

Javascript


<script>
function changeValue(val)
{
 document.getElementById('selector').innerHTML = val;
}
</script>


So there you have it, the complete code is below:


Complete Code


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Custom Select box</title>
<script>
function changeValue(val)
{
 document.getElementById('selector').innerHTML = val;
}
</script>
<style>
.selection { position:relative; }

.selectbox,#selector {
 position:absolute;
 top:0;
 left:0;
 font-family:Arial, Helvetica, sans-serif;
 font-size:15px;
}

.selectbox {
 width:220px;
 padding:5px;
 height:30px;
 opacity:0;
 z-index:5;
}

#selector {
 background-image:url(dropdown.jpg);
 background-repeat:no-repeat;
 padding:5px 43px 5px 10px;
 overflow:hidden;
 width:162px;
 height:20px;
 color:#fff;
}
</style>
</head>

<body>
<div class="selection">
    <select class="selectbox" onchange="changeValue(this.value);">
        <option>test select</option>
        <option>test select 2</option>
        <option>test select 3</option>
        <option>test select 4</option>
        <option>test select 5</option>
    </select>
    <span id="selector">test select</span>
</div>
</body>
</html>

Wednesday 14 March 2012

How to secure HTML5 video

With videos being used everywhere, more and more websites are trying to accommodate videos on their website, if it's for visual tutorials, or marketing. Sometimes though you don't want your video being downloaded and shared with others.. A good case for this would be a subscription based website.

Easy, lets use a flash player.. well ok, we could do.. but with more and more websites jumping over to HTML5 compliant, it would be nice if we could protect our videos and still use the HTML5 player.

The key issues with using an HTML5 player is there is absolutely NO encryption or protection for the videos.

Here's an example of the HTML5 video tag

<video controls>
    <source src="/sample.mp4" type="video/mp4" />
    <source src="/sample.webm" type="video/webm" />
</video>
All a viewer has to do is right click on the playing video and hit a button called 'Save Video As' and they'll have it on their computer. If not they can see exactly where the video is stored and download it anyway.

Protecting the video is a very complex method using multiple checks on multiple technologies, i won't go into the details..

We have spent hours, ounces (of coffee), an unmeasurable amount of stress developing this HTML5 protection.

After a lot of agressive testing we have secured our videos and have developed a very smart detection system which adapts to different download attempts.

And so from the creators of The Skyblue Transporter and The Custom Google +1 button we are proud to announce that we will be releasing Version 1 of our SkyblueVideoProtection (SkyBVP) on a cloud based subscription where you can securely store and stream your videos embedded directly to your website.. For more information please enquire!