Tuesday 26 June 2012

CSS3 Lasers!

Jeff Broderick makes some pretty awesome work. I stumbled upon this dribbble shot of his portfolio design (below). I thought the laser effect was pretty cool, so I clicked on the link tohis site. Alas, the laser effect was only for the dribbble shot and the page had a dissolve effect for the transitions instead.




I figured it would be easy enough to make in CSS3, so I decided to give it a try. Hover over the image on the left and see the magic at work. Please note, I have only taken the time to make this compatible with webkit based browsers. If you’re interested to see how this works, below is a bit of the code.


<div class="item">
    <div class="hover">
        <div class="laser"></div>
    </div>
    <img class="background" src="background.png"/>
</div>
.item {
    position: relative;
    width: 475px;
    height: 400px;
    margin: 50px auto;
}
 
.background {
    position: absolute;
    z-index: 1;
    width: 475px;
    height: 400px;
    display: block;
}
 
.hover {
    height:0%;
    background: url(hover.png) no-repeat;
    position: absolute;
    z-index: 2;
    -webkit-transition: height 1s ease;
    width: 100%;
    -webkit-background-size: 475px 400px;
}
 
.item:hover .hover {
    height: 100%;
}
 
.laser {
    height: 3px;
    width: 100%;
    background: red;
    display: block;
    position: absolute;
    bottom: -2px;
    -webkit-border-radius: 50%;
    box-shadow: 0 0 20px 10px red;
    -webkit-transition: opacity .25s ease;
    opacity: 0;
    -webkit-transition-delay: .75s;
}
 
.item:hover .laser {
    opacity: 1;
    -webkit-transition-delay: 0s;
}

No comments:

Post a Comment