- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
这是我的 html:
<div id="body">
<div id="body-inner">
<div class="game" id="csgo" onclick="window.location='https://csgo.fraid.gg/'"><div class="game-handle"></div></div>
<div class="game" id="minecraft" onclick="window.location='https://mc.fraid.gg/'"><div class="game-handle"></div></div>
<div class="game" id="lineage" onclick="window.location='https://l2.fraid.gg/'"><div class="game-handle"></div></div>
</div>
</div>
这是我的CSS:
.game {
width: 807px;
height: 607px;
filter: drop-shadow(10px 10px 32px black) opacity(50%) grayscale(80%);
margin: auto;
margin-left: -220px;
margin-right: -220px;
transform: scale(0.7,0.7);
transition: 150ms ease-in-out;
position: relative;
z-index: 99;
}
.game#csgo {
background: url('game-csgo.png') no-repeat rgba(0,255,0,0.5);
background-size: 100%;
}
.game#minecraft {
background: url('game-minecraft.png') no-repeat rgba(0,255,0,0.5);
background-size: 100%;
}
.game#lineage {
background: url('game-l2.png') no-repeat rgba(0,255,0,0.5);
background-size: 100%;
}
.game.hover {
filter: drop-shadow(20px 20px 64px black) opacity(100%) grayscale(0%);
transform: scale(1,1);
transition: 150ms ease-in-out;
}
.game-handle {
width: 411px;
height: 525px;
cursor: pointer;
position: fixed;
bottom: 0;
left: 198px;
z-index: 99999;
background: rgba(255,0,0,1);
}
切换 .hover 类的 jQuery 脚本:
jQuery(function() {
jQuery('.game-handle').mouseenter(function() {
jQuery(this).parent('.game').addClass('hover',0);
}).mouseleave(function() {
jQuery(this).parent('.game').removeClass('hover',0);
});
});
关键是红色部分是我想要注册鼠标悬停事件的部分。但是紧挨着前面的 div,从左到右,也与红色区域重叠! :( 绿色部分是本身包含背景的 div。知道如何将所有红色 div 放到绝对前面吗?
(我这样做的唯一原因是因为客户想要“卡片”,上面挂着剑、枪、 ARM 等东西,然后主 div 的宽度必须更大并且双方都有负边距)
屏幕:
fiddle 示例:https://jsfiddle.net/9yy2csvd/
问题:
光标位于红色部分,但右侧 div 的绿色与其重叠(未触发 mouseenter 事件)。所以你必须用光标向左移动更多,这样你就只能触摸红色部分(并触发事件)。但我需要红色部分位于所有绿色之上,
类.game的div的每个背景看起来是这样的:
我需要只有当我将鼠标光标移到“卡片”本身上时,而不是它周围的透明背景(包括伸出“卡片”的图片部分)时,事件才会被触发。
最佳答案
这很复杂。
z-index
通常何时工作?z-index
在具有 z-index
的最近父级范围内工作。换句话说,如果这个 child 的 parent 设置了 z-index
,您永远不能让 child 高于其他 parent 。
根据我的个人测试,我得出结论,您确实可以达到预期的效果,只要您不使用以下任何一种:
z-index
转换
过滤器
事实证明,上面列表中的每个属性都会破坏结果。
z-index
何时按您的预期工作或不工作有很多变数。我准备了一个测试环境供您试用。请注意它何时损坏以及您可以应用什么属性来修复它。
$(function() {
$('body').addClass('child-relative'); // Simplest combination when it works
$('label input').click(function() {
var className = $(this).data('class');
$('body').toggleClass(className);
}).each(function() {
var className = $(this).data('class');
$(this).attr({
checked: $('body').hasClass(className)
});
});
});
/*/ "Works" = .child is above all .parent-s /*/
/*/ Basic styles /*/
.parent {
outline: 2px dotted blue;
background: rgba(0, 0, 255, .2);
width: 200px;
height: 200px;
float: left;
margin-right: -50px;
}
.child {
background: yellow;
outline: 2px dashed red;
width: 150px;
height: 150px;
margin: 25px;
}
/*/ Variables /*/
.parent-relative .parent {
/* Works when .child has position: relative/absolute; AND z-index > 0 */
position: relative;
}
.parent-z-index .parent {
/* Never works */
z-index: 0;
}
.parent-transform .parent {
/* Never works */
transform: scale(1);
}
.parent-transform-rotate .parent {
/* Never works */
transform: rotate(360deg);
}
.parent-filter .parent {
/* Never works */
filter: opacity(100%);
}
.child-relative .child {
/* Works when .parent has only position: static; OR when .child has z-index as well */
position: relative;
}
.child-z-index .child {
/* Works when .parent has position: static; OR position: relative; WITHOUT z-index */
z-index: 1;
}
.child-transform .child {
/* Doesn't matter */
transform: scale(1);
}
.child-transform-rotate .child {
/* Doesn't matter */
transform: rotate(360deg);
}
.child-filter .child {
/* Doesn't matter */
filter: opacity(100%);
}
/*/ Ignore following code /*/
h2 {
margin-bottom: 0;
}
.parent {
margin-top: 20px;
}
.controls .bad {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<h2><code>.parent { }</code></h2>
<div class="controls">
<label>
<input type="checkbox" data-class="parent-relative">
<code>position: relative;</code>
</label>
<label class="bad">
<input type="checkbox" data-class="parent-z-index">
<code>z-index: 0;</code>
</label>
</div>
<div class="controls">
<label class="bad">
<input type="checkbox" data-class="parent-transform">
<code>transform: scale(1);</code>
</label>
<label class="bad">
<input type="checkbox" data-class="parent-transform-rotate">
<code>rotate: scale(360deg);</code>
</label>
<label class="bad">
<input type="checkbox" data-class="parent-filter">
<code>filter: opacity(100%);</code>
</label>
</div>
<h2><code>.child { }</code></h2>
<div class="controls">
<label>
<input type="checkbox" data-class="child-relative">
<code>position: relative;</code>
</label>
<label>
<input type="checkbox" data-class="child-z-index">
<code>z-index: 1;</code>
</label>
</div>
<div class="controls">
<label>
<input type="checkbox" data-class="child-transform">
<code>transform: scale(1);</code>
</label>
<label>
<input type="checkbox" data-class="child-transform-rotate">
<code>rotate: scale(360deg);</code>
</label>
<label>
<input type="checkbox" data-class="child-filter">
<code>filter: opacity(100%);</code>
</label>
</div>
<div class="parent">
<div class="child">
Child 1
</div>
</div>
<div class="parent">
<div class="child">
Child 2
</div>
</div>
<div class="parent">
<div class="child">
Child 3
</div>
</div>
请记住,我只在 Windows 上的 Chrome 中对此进行了测试。也许在其他环境中,标记为 .bad
的属性可以正常工作。我会留下详细的测试供您执行! ;-)
祝你有美好的一天!
~维克托
关于jquery - CSS:DIV 重叠,z-index 不修复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41652580/
我在一个C++程序中找到了一段代码,好像每隔for()循环两次。在这个程序中循环,但为什么在这样的预处理器定义中需要第三个 for 呢? #define for for(int z=0;z<2;++z
我正在尝试分割其中有一个小写字母后跟一个大写字母的文本。 假设文本是: “Įvairių rūšiųSkinti kardeliai” 我想在“ųS”处拆分它,但是以下正则表达式“[ą-ž][Ą-Ž]
这个问题在这里已经有了答案: Reference - What does this regex mean? (1 个回答) 关闭 2 年前。 下面的正则表达式有什么区别。对我来说,它们都是一样的 [
我正在尝试用 Java 编写一个正则表达式: "/[A-Z]{6}-[A-Z]{4}-[A-Z]{4}/" 但是它不起作用。例如 "AASAAA-AAAA-AAAA".matches("/[A-Z]{
我需要确定一个字符串是否是一个变量标识符。 即(a-z,A-Z,,$) 后跟 (a-z,A-Z,0-9,,$) 我知道我可以使用手动配置的 reg exp 来完成它,但必须有一个更紧凑的内置函数我可以
早上好,我是新来的,我带来了一个小问题。我无法针对以下问题开发有效的算法:我需要找到三个正数 x、y 和 z 的组合,以便 x + y、x - y、y + z、y - z、x + z 和 x - z
这个问题已经有答案了: How does the ternary operator work? (12 个回答) 已关闭 6 年前。 我发现了一种不同的返回值的方式,并且很兴奋。它到底是什么意思? 如
我需要以下正则表达式,允许 [a-zA-Z]+ 或 [a-zA-Z]+[ \\-]{0,1}[a-zA-Z]+ 所以我想在 a-zA-Z 字符之间允许无限的减号和空格 示例: sdfsdfdsf-sf
我正在编写一个代码,它以“代码”(编码理论)作为输入,并且我已经计算了它的权重枚举器。我想使用 MacWilliams Identity 找到双代码的权重枚举器. 我有W(z) ,代码的权重枚举器,我
我已经编写了一个 child 文字游戏,现在我正在尝试优化性能。游戏以一种特殊的方式从数据库中挑选关键词,我想做得更好。 给定一个按字母数字排序的 MySQL 关键字字段: keyword s
假设一个字符串是abc/xyz/IMPORTANT/DATA/@#!%@!%,我只想要IMPORTANT/DATA/!%#@%!#% 我对正则表达式很烂,而且真的还没学过 JavaScript API
JS代码: ? 1
大家晚上好我想知道有没有更快的方法来生成以下形式的列表? [a,b,c,…,z] → [[z], [y,z], [x,y,z], … , [a,b,…,y,z]] 我知道切片是最好的方法之一,但没有更
我在 Firefox 和其他浏览器上遇到嵌套 z-index 的问题,我有一个 div,z-index 为 30000,位于 label 下方> zindex 为 9000。我认为这是由 z-inde
我正在尝试制作一个灯泡。这是代码 JSfiddle HTML 查询 $('.button').click(function() { $('#add').show();
在您想将嵌套模块导入命名空间的情况下,我总是这样写: from concurrent import futures 不过,我最近意识到这也可以使用“as”语法来表达。请参阅以下内容: import c
我正在尝试创建一个基本上复制 matlab 命令的函数:[z;-z] 其中 z = randn(m,n) 返回一个 m -by-n 随机条目矩阵。我能够在 C++ 中为下面的 randn 函数创建一个
好吧,我迷失在这些指针中,有人能准确地告诉我 char * x,y,z; 和 char* x,y,z 之间的区别是什么; 和 char (*)x,y,z; ?如果可以,请为您的答案或其他内容提供资源。
这是一道函数依赖题。 我知道当 x->yz 然后 x->y 和 x->z 时。但是上面的依赖关系可能吗? 最佳答案 If xy determines z can x determine z and y
我有一个列表列表 nLedgers - 一个 3D 点云: [nodeID, X, Y, Z] 多行。一些节点将具有相同的 X 和 Y 坐标以及不同的 Z 坐标。 我想首先确定具有相同 X 和 Y 坐
我是一名优秀的程序员,十分优秀!