如何使背景可点击 [英] How can I make a background clickable

查看:118
本文介绍了如何使背景可点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求为我们的某个网站制作赞助背景(网站收购),并出现了是否可以点击平铺背景中的标志的问题。

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.

我最初的想法是不,但我想到的越多,我想越可能如果我使用JavaScript,使body元素可点击,或假的背景图像作为一个层下面

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;">...


推荐答案

您需要注意IE和Mozilla之间的事件顺序(事件捕获与冒泡)的区别。如果您有一个带有onClick事件的元素,其本质上占用整个页面,然后其他可点击元素位于其顶部,则单击其中一个元素可能会导致BOTH事件触发,这可能不是预期的功能。

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 解释比我能做的更好。

PPK explains it better than I can.

这篇关于如何使背景可点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆