我可以使悬停不可见的元素吗?

2023-11-29前端开发问题
4

本文介绍了我可以使悬停不可见的元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个具有星爆效果的 div(透明 png 背景),我想在它们悬停时覆盖在一系列 imgs 上;我必须使 div 变大以包含图像,但它会妨碍检测图像上的悬停.(我将它们全部作为背景图像,因此它们是通过高分辨率 css 媒体查询加载的)

I have a div that has a starburst kind of effect (transparent png background) that I want to overlay on a series of imgs as they are hovered; I have to make the div large to contain the image, but then it gets in the way of detecting the hovers on the images. (I have them all as background images so they're loaded via a high resolution css mediaquery)

每个图像"都是一系列元素,现在看起来像这样:

Each 'image' is a series of elements looks like this right now:

<div class="section">
    <div class="starburst"></div>
    <a href="link">
        div class="image">
            <div class="non-hover"></div>
            <div class="hover"></div>
        </div>
        <p>Caption</p>
    </a>
</div>

JS是这样的

$('.section a').hover(
    function () {
        $('.speaker .hover').hide();
        $(this).find('.non-hover').addClass('focus');
        $(this).find('.hover').stop().show().animate({opacity:1.0}, 1000);
    },
    function () {
        $(this).find('.hover').stop().animate({opacity:0.0}, 0);
        $(this).find('.non-hover').removeClass('focus');
    }
);

我的问题是将 .starbursts 放在哪里,如何处理它们以使它们在前面,它们的 bg 图像位于悬停图像的顶部,但不会妨碍悬停在它们上面.我不确定这是否可能,但希望有办法.让它们分开,因为我想以不同的方式为它们制作动画.

My question is where to put the .starbursts, how to deal with them so that they are in front, with their bg image on top of the hovered image, but doesn't get in the way of hovering on them. I'm not sure this is even possible but hoping there's a way. Have them separated because I want to animate them on differently.

推荐答案

你可以使用 CSS 指针事件 属性:

You can use the CSS pointer-events property:

CSS 属性 pointer-events 允许作者控制特定图形元素在什么情况下(如果有)可以成为鼠标事件的目标.

The CSS property pointer-events allows authors to control under what circumstances (if any) a particular graphic element can become the target of mouse events.

.starbursts {
   pointer-events: none
}

这篇关于我可以使悬停不可见的元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

如何使用百度地图API获取地理位置信息
首先,我们需要在百度地图开放平台上申请一个开发者账号,并创建一个应用。在创建应用的过程中,我们会得到一个密钥(ak),这是调用API的凭证。 接下来,我们需要准备一个PHP文件,以便可以在网页中调用。首先,我们需要引入百度地图API的JS文件,代码如下...
2024-11-22 前端开发问题
244

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

layui中表单会自动刷新的问题
layui中表单会自动刷新的问题,因为用到layui的表单,遇到了刷新的问题所以记录一下: script layui.use(['jquery','form','layer'], function(){ var $ = layui.jquery, layer=layui.layer, form = layui.form; form.on('submit(tijiao)', function(data){ a...
2024-10-23 前端开发问题
262

JavaScript小数运算出现多位的解决办法
在开发JS过程中,会经常遇到两个小数相运算的情况,但是运算结果却与预期不同,调试一下发现计算结果竟然有那么长一串尾巴。如下图所示: 产生原因: JavaScript对小数运算会先转成二进制,运算完毕再转回十进制,过程中会有丢失,不过不是所有的小数间运算会...
2024-10-18 前端开发问题
301

jQuery怎么动态向页面添加代码?
append() 方法在被选元素的结尾(仍然在内部)插入指定内容。 语法: $(selector).append( content ) var creatPrintList = function(data){ var innerHtml = ""; for(var i =0;i data.length;i++){ innerHtml +="li class='contentLi'"; innerHtml +="a href...
2024-10-18 前端开发问题
125