【发布时间】:2020-02-14 12:30:00
【问题描述】:
我正在努力找出如何在我的自定义光标位于 iframe 上时隐藏它。
我设计了一个自定义光标,但它在所有网页部分都可以正常工作。但是,当它越过 Vimeo iframe 时,鼠标会停留在 iframe 的边缘并显示默认的网络浏览器光标。
我认为最简单的方法是在 iframe 上进行鼠标悬停时隐藏自定义光标。
试图通过使用 CSS(当自定义光标在 iframe 上时应用 display:none)和 js 来弄清楚,但没有成功。
这里是codepen中的代码:https://codepen.io/felixgonzalo/pen/vYOLrVJ
这是代码: JS
let mouseCursor = document.querySelector(".cursor");
let Links = document.querySelectorAll("a");
let logo = document.querySelector(".logo-error");
window.addEventListener('mousemove', cursor);
function cursor(e){
mouseCursor.style.top = e.pageY + "px";
mouseCursor.style.left = e.pageX + "px";
}
Links.forEach(link =>{
if ( link !== logo ){
link.addEventListener("mouseleave", () => {
mouseCursor.classList.remove("link-grow");
});
link.addEventListener("mouseover", () => {
mouseCursor.classList.add("link-grow");
});
}
});
CSS
body{
cursor: none;
}
.cursor{
width: 2rem;
height: 2rem;
border: 2px solid white;
border-radius: 50%;
position: absolute;
transform: translate(-50%, -50%);
transition: all 0.3s ease;
transition-property: background, transform;
transform-origin: 100% 100%;
z-index: 20000;
pointer-events: none;
}
.link-grow{
transform: scale(1.2);
background: white;
mix-blend-mode: difference;
}
a:-webkit-any-link {
cursor: none;
}
.logo-error:hover .cursor{
display: none !important;
}
@media (max-width: 768px){
.cursor {
display: none;
}
}
【问题讨论】:
标签: javascript jquery css iframe mouseevent