简体   繁体   English

使背景雪花元素不可点击

[英]Make background snowflake element unclickable

I have added a snowflake effect to my website to make snowflakes fall in the background on the homepage (Got code from https://www.kirupa.com/html5/the_falling_snow_effect.htm ). 我已在网站上添加了雪花效果,以使雪花落在首页的背景上(Got代码来自https://www.kirupa.com/html5/the_falling_snow_effect.htm )。 It works by adding the following block of code: 通过添加以下代码块,它可以工作:

<div id="snowflakeContainer">
     <p class="snowflake">*</p>
</div>

It then styles the '*' to make it look like a snowflake and then sets it to fall in the background. 然后,对'*'设置样式,使其看起来像雪花,然后将其设置为落在背景中。 However, my issue is that if you try to click something on my homepage, sometimes a snowflake will fall in front of the curser therefor not allowing the user to select the element of which they are attempting to do. 但是,我的问题是,如果您尝试单击主页上的某些内容,有时雪花会落在光标上方,从而不允许用户选择他们要尝试执行的元素。

Is there a way of making it so the falling snowflake doesn't get in the way? 有没有办法使落下的雪花不会挡住?

Set the pointer events property on the snowflakes to none. 将雪花上的指针事件属性设置为none。

p.snowflake {
  pointer-events: none;
}

You can add the css property pointer-events: none to your element, which prevents any pointer events from interacting with the element. 您可以将css属性的pointer-events: none到您的元素,以防止任何指针事件与该元素进行交互。

Your css selector would now look like this: 您的css选择器现在将如下所示:

.snowflake {
    padding-left: 15px;
    font-family: Cambria, Georgia, serif;
    font-size: 14px;
    line-height: 24px;
    position: fixed;
    color: #FFFFFF;
    user-select: none;
    z-index: 1000;
    pointer-events: none;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM