gpt4 book ai didi

javascript - 自定义光标卡在左上角

转载 作者:行者123 更新时间:2023-12-04 08:10:40 25 4
gpt4 key购买 nike

我在使用混合模式排除制作自定义光标时遇到问题。我尝试了几种技术,但出于某种奇怪的原因,我添加了一个带有混合模式的光标,但是它只显示在我页面的左上 Angular 并且不会移动。我希望它成为主光标,但不知道如何修复它。
代码笔:https://codepen.io/ryanforprez/pen/vYyEWyL

    .cursor {
position: fixed;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #ffff;

mix-blend-mode: difference;
z-index: 999;

transition: transform 0.2s;
}

html,
* {
cursor: none;
pointer-events: none;

}



<html>
<body onclick='window.location.href="work.html"'>

</body>
</html>

<body>

<div class="nav">

<div class="name"><a href="work.html">Ryan Stewart</a></div>
<div class="info"><a href="information.html">Information</a></div>

</div>

<div class="contact"> <a href="work.html">Click anywhere to enter.</a>
</div>



<marquee width="100%" direction="left" scrollamount="15" behavior="scroll">Ryan Stewart: Graphic Design, Art Direction, Letterform Design</marquee>



  <script>$(document).ready(function() {
$(".hamburger-menu-button").click(function() {
$(".main-box").toggleClass("main-box-clicked");
$(".hamburger-box").toggleClass("hamburger-box-clicked");
});

var cursor = $(".cursor");

$(window).mousemove(function(e) {
cursor.css({
top: e.clientY - cursor.height() / 2,
left: e.clientX - cursor.width() / 2
});
});

$(window)
.mouseleave(function() {
cursor.css({
opacity: "0"
});
})
.mouseenter(function() {
cursor.css({
opacity: "1"
});
});

$(".link")
.mouseenter(function() {
cursor.css({
transform: "scale(3.2)"
});
})
.mouseleave(function() {
cursor.css({
transform: "scale(1)"
});
});

$(window)
.mousedown(function() {
cursor.css({
transform: "scale(.2)"
});
})
.mouseup(function() {
cursor.css({
transform: "scale(1)"
});
});
});</script>

最佳答案

我认为这是因为您有多个打开和关闭正文和 html 标签,简而言之,因为您的代码很困惑。遵循正确缩进、清理和工作的版本:

$(document).ready(function() {
$(".hamburger-menu-button").click(function() {
$(".main-box").toggleClass("main-box-clicked");
$(".hamburger-box").toggleClass("hamburger-box-clicked");
});

var cursor = $(".cursor");

$(window).mousemove(function(e) {
cursor.css({
top: e.clientY - cursor.height() / 2,
left: e.clientX - cursor.width() / 2
});
});

$(window)
.mouseleave(function() {
cursor.css({
opacity: "0"
});
})
.mouseenter(function() {
cursor.css({
opacity: "1"
});
});

$(".link")
.mouseenter(function() {
cursor.css({
transform: "scale(3.2)"
});
})
.mouseleave(function() {
cursor.css({
transform: "scale(1)"
});
});

$(window)
.mousedown(function() {
cursor.css({
transform: "scale(.2)"
});
})
.mouseup(function() {
cursor.css({
transform: "scale(1)"
});
});
});
.cursor {
position: fixed;
width: 20px;
height: 20px;
border-radius: 50%;
background-color: #cccc;

mix-blend-mode: difference;
z-index: 999;
transition: transform 0.2s;
}

* {
cursor: none;
pointer-events: none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="nav">
<div class="name">
<a href="work.html">Ryan Stewart</a>
</div>
<div class="info">
<a href="information.html">Information</a>
</div>

</div>
<div class="contact">
<a href="work.html">Click anywhere to enter.</a>
</div>
<marquee width="100%" direction="left" scrollamount="15" behavior="scroll">Ryan Stewart: Graphic Design, Art Direction, Letterform Design</marquee>
<div class="cursor"></div>

关于javascript - 自定义光标卡在左上角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65983696/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com