3

Is there an easy way to have a "glass pane" all over the HTML page, regardless of zoom/slide events/platform/browser{mobile/desktop}?

By "easy" I mean something like pure CSS support, not a plug-in.

Fallback: plug-in advice might be useful as well.

Thanks

BreakPhreak
  • 10,940
  • 26
  • 72
  • 108

3 Answers3

6

If you just mean a layer on top of everything, try this:

#top-layer {
    position: fixed;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    top: 0;
    left: 0;
}

You can set opacity: 0.5; if you want it semi-transparent.

A jsFiddle example

MMM
  • 7,221
  • 2
  • 24
  • 42
  • in that case `height` will relate to viewport only, I'd like the scroll event to be supported as well (i.e. after scrolling down, the glass pane should remain visible and not just shift up). – BreakPhreak Jan 31 '12 at 12:32
  • do you know by chance - will `fixed` it support mobile browsers as well? AFAIK Mobile Safari on iOS5 might have probs with that. – BreakPhreak Jan 31 '12 at 12:36
  • [IOS5 has support](http://davidbcalhoun.com/2011/new-mobile-safari-stuff-in-ios5-position-fixed-overflow-scroll-new-input-type-support-web-workers-ecmascript-5) for `position: fixed;`, other mobile platforms might complaint, so you can use [iScroll](http://cubiq.org/iscroll) – MMM Jan 31 '12 at 12:39
  • 1
    Look at [this solution](http://stackoverflow.com/questions/2784889/android-web-app-positionfixed-broken) or use iScroll as I've suggested. – MMM Jan 31 '12 at 12:54
3

I would use a class to do this.

div.glass-pane {
    width: 100%;
    height: 100%;
    z-index: 10;
    position: fixed;
    top: 0;
    left: 0;
    margin: 0;
    padding: 0;
}

You can change the height, width, top, and left position to make the "glass pane" only fit over a certain area. Also you can add some color (rgba or hsla would be the best and create a glass effect). The z-index will help if you want to create a modal box on top of the pane. Then just use jQuery to add click events.

I recently published a Chrome Extension that uses this effect (here is the source).

jjNford
  • 5,170
  • 7
  • 40
  • 64
1

A glass pane? Try this CSS:

div#glassPane {
   height: 98%;
   width: 98%;
   border: 1px solid rgba(0,0,0,0.5);
   border-radius: 10px;
   background: rgba(0,0,0,0.25);
   box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px rgba(255,255,255,0.3), inset 0 10px rgba(255,255,255,0.2), inset 0 10px 20px rgba(255,255,255,0.25), inset 0 -15px 30px rgba(0,0,0,0.3);
   position: fixed;
   top: 1%;
   left: 1%;
}

See here for an example: http://jsfiddle.net/vLTWK/

See here for more:
http://dev.opera.com/articles/view/beautiful-ui-styling-with-css3-text-shadow-box-shadow-and-border-radius/#glassbox

Shane
  • 2,007
  • 18
  • 33