【发布时间】:2016-09-02 13:49:18
【问题描述】:
我一直在尝试获得一个输出,其中图像被遮盖在双目形状的元素内。圆形部分随着鼠标光标移动,无论鼠标走到哪里,它都会显示图像的一部分。还需要设置鼠标不离开主容器。
其余部分将保持黑色,只有元素在鼠标移动时以该形状可见。
我已经尝试了以下代码:
$('.clipping-cursor').on('mousemove', function(e) {
var parentOffset = $(this).parent().offset();
var relativeXPosition = (e.pageX - parentOffset.left); //offset -> method allows you to retrieve the current position of an element 'relative' to the document
var relativeYPosition = (e.pageY - parentOffset.top);
$('.clipping-cursor').css({
left: relativeXPosition,
top: relativeYPosition
});
});
.collaborate-wrapper {
width: 100%;
height: 90vh;
background: #000;
overflow: hidden;
position: relative;
}
.clipping-cursor {
width: 1000px;
height: 580px;
box-sizing: border-box;
position: absolute;
margin-top: -290px;
margin-left: -500px;
background-image: url('../images/background/collaborate-2.svg');
background-repeat: no-repeat;
background-size: container;
background-attachment: fixed;
background-position: center center;
-webkit-mask-image: url('../images/masking-circle.svg');
-webkit-mask-size: 100%;
-webkit-mask-repeat: no-repeat;
-webkit-mask-position: center;
border: 1px solid #fff;
cursor: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="collaborate-wrapper">
<div class="clipping-cursor">
</div>
</div>
【问题讨论】:
-
我想你可能想要一个包含两个圆圈的 clipPath 而不是蒙版。