Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fade edges of div with jQuery

Tags:

jquery

fade

How can I fade edges of a div with jQuery? Think of a carousel with images inside that slides horizontally. How can I fade out the left and right sides so that images near the edges disappears gradually.

Hope it's clear. :)

like image 706
Sandro Antonucci Avatar asked Aug 15 '10 21:08

Sandro Antonucci


1 Answers

Webkit browsers (i.e. Chrome and Safari) support a CSS property called -webkit-mask, which allows you to overlay an element with a CSS3 effect (i.e. a linear gradient).

The following stylesheet rule will apply a fading white edge to elements with the class .mask:

 .mask {
     -webkit-mask: -webkit-linear-gradient(
          left,
         rgba(255,255,255,0),
         rgba(255,255,255,1) 5%,
         rgba(255,255,255,1) 95%,
         rgba(255,255,255,0)
     );
 }

Unfortunately, this will only work in webkit-based browsers. If you want to support everything else (which you probably do), you might be best using transparent PNGs.

like image 64
Jim O'Brien Avatar answered Sep 22 '22 00:09

Jim O'Brien