Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a background clickable

Tags:

html

jquery

css

I've been asked to make a sponsored background (site takeover) for one of our sites and the question arose of whether I can make the logos in the tiled background clickable.

My initial thought was 'no', but the more I think about it, the more I think it'd be possible if I either used JavaScript to make the body element clickable, or fake the background image as a layer below the content and make that clickable.

Has anyone done this before with success with one of these approaches or a different one?

jQuery:

$('body').click()

HTML:

<body>
  <div id="sponsors-div" style="position:fixed;z-index:0;"><a style="display:block;height:100%" href="http://sponsors.url"></a></div>
  <div id="site-container" style="position:relative;z-index:1;">...
like image 387
Steve Perks Avatar asked Oct 27 '25 03:10

Steve Perks


1 Answers

You'd need to be careful around event order (event capturing vs. bubbling) differences between IE and Mozilla. If you have an element with an onClick event that essentially takes up the entire page, and then other clickable elements on "top" of it, clicking on one of those elements can cause BOTH events to fire, which is likely not the intended functionality.

PPK explains it better than I can.

like image 195
Scott Avatar answered Oct 28 '25 16:10

Scott