【发布时间】:2017-03-07 20:32:16
【问题描述】:
我需要从光标位置在div 中获得悬停效果。
我有这个html 和css
.f {
width: 200px;
height: 200px;
background-color: grey;
position: fixed;
border-radius: 100px;
}
.s {
width: 50px;
height: 50px;
background-color: black;
border-radius: 100px;
margin: 75px 0px 0px 75px;
transition: width 1s, height 1s, margin 1s;
}
.s:hover {
width: 100px;
height: 100px;
background-color: black;
margin: 50px 0px 0px 50px;
}
<div class="f">
<div class="s"></div>
</div>
我需要这样的东西:
我对 js 或 jquery 解决方案持开放态度。
编辑
我有一个 jquery 解决方案:
$("div.f").mousemove(function(e) {
$('div.s').css({
left: e.clientX - 28,
top: e.clientY - 24
});
});
.f {
width: 200px;
height: 200px;
background-color: grey;
position: fixed;
border-radius: 100px;
/* comment or remove the overflow if necessary */
overflow: hidden;
}
.s {
position: absolute;
width: 50px;
height: 50px;
background-color: black;
border-radius: 100px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="f">
<div class="s"></div>
</div>
但我需要圆圈像第一个 sn-p 一样制作过度动画。
原问题here
【问题讨论】:
-
您是否正在尝试定位黑色圆圈以使其“跟随”光标?
-
不完全是,我尝试当我进入 div 时,悬停效果出现在光标位置
-
您可能需要使用 javascript 来执行此操作,因为 CSS 中的悬停事件只能应用静态样式。
-
Here is something similar。这个方法是用hitboxes完成的,只有css,添加许多div来检测光标的位置。更好的方法是使用javascript,这里是one example
-
如果你对 js 解决方案持开放态度,你应该用 js 标记你的问题
标签: javascript jquery html css