/    Sign up×
Community /Pin to ProfileBookmark

Change the custom cursor on hover

Hello,

I am created custom mouse cursor from 2 divs as (>) with jQuery, now I want to change the style of the custom cursor when hovering over div.

Here is my code:

[code=html]
<!DOCTYPE html>
<html>
<head>
<script src=”try.js”></script>
<style type=”text/css” media=”screen”>
.verline, .horline {
border-radius: 20%;
background-color: #121212;
position :absolute;
animation-duration: 400ms;
animation-timing-function: ease-out;
animation-iteration-count: 1;
animation-direction: normal;
animation-fill-mode: forwards;
}
.horline {
width: 50px;
height: 3px;
top: -3px;
left: -25px;
animation-name: hormove;
}
.verline {
width: 3px;
height: 50px;
top: -27px;
left: -2px;
animation-name: vermove;
}
@keyframes hormove {
0% { transform: rotate(0deg); top: -3px; left: -25px; }
100% { transform: rotate(220deg); top: -19px; left: -25px; }
}
@keyframes vermove {
0% { transform: rotate(0deg); top: -27px; left: -2px; }
100% { transform: rotate(50deg); top: -12px; left: -2px; }
}
#hoverit {
width: 200px;
height: 200px;
background: red;
}
</style>
</head>
<body>
<div id=”cursor”>
<div class=”horline”></div>
<div class=”verline”></div>
</div>
<div id=”hoverit”></div>
</body>
<script>
var ElementCursor = {
cursorElement: “”,
setCursor: function (cursorId) {
$(‘html’).css({
‘cursor’: ‘none’
});
$(‘html’).mousedown(function (e) {return false;});
ElementCursor.cursorElement = cursorId;
ElementCursor.updateCursor();
},
removeCursor: function () {
$(‘html’).css({
‘cursor’: ”
});
ElementCursor.cursorElement = ”;
},
updateCursor: function () {
$(document).mousemove(function (e) {
$(‘#’ + ElementCursor.cursorElement).css({
‘position’: ‘fixed’,
‘top’: e.pageY + ‘px’,
‘left’: e.pageX + ‘px’
});
});
}
};
ElementCursor.setCursor(“cursor”);
</script>
</html>
[/code]

I hope this can be done

Thank you

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@rootFeb 17.2017 — Wrong forum.

You are asking a CSS question in a JavaScript forum.

Also note that if it is JQuery you are looking at using, then you are still in the wrong forum, JQuery questions go in the JavaScript Frameworks forum.
Copy linkTweet thisAlerts:
@khalil111authorFeb 17.2017 — Wrong forum.

You are asking a CSS question in a JavaScript forum.

Also note that if it is JQuery you are looking at using, then you are still in the wrong forum, JQuery questions go in the JavaScript Frameworks forum.[/QUOTE]


I am looking for javascript code that makes a change to the cursor style (background color of the cursor for example) when the cursor is over a div.

I couldn't achieve that with css, because I can't animate the keyframe style of the mouse cursor when hovering over a div.

Exactly I have 2 divs makes the shape of + inside on container div, and that container div is my mouse cursor now, so now I need this + to animate to be > when I hover to right of the page and to animate to be < when I hover to the left.

My code I show, I achieve to make the cursor already, now I am looking to animate it when hovering.

Thank you
Copy linkTweet thisAlerts:
@Kevin2Feb 17.2017 — Looking through your code I don't see where you are calling a jQuery library. Won't work without it.

Edit and PS: Your HTML is invalid. You can look up why. https://validator.w3.org/
Copy linkTweet thisAlerts:
@khalil111authorFeb 17.2017 — I am sorry I didn't link the Jquey link as I make it internal link, here is the code with proper head link

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

instead of <script src="try.js"></script>

Thank you
Copy linkTweet thisAlerts:
@Kevin2Feb 17.2017 — To be brutally honest this is wasted time on your part. 50% or more of your users (phones/tablets/other touchscreens) will never see that "custom cursor" while having to load all the code necessary to make it work. Be nice to them and drop it.
Copy linkTweet thisAlerts:
@khalil111authorFeb 17.2017 — Thanks for the advice, but my target users mostly will open in it on desktop, please check this https://yoocon.de/work/carrera-shop.php
Copy linkTweet thisAlerts:
@TrainFeb 17.2017 — load time 54 seconds. Not good as I usually leave after 10 seconds.

Check attachment.

[canned-message]attachments-removed-during-migration[/canned-message]
Copy linkTweet thisAlerts:
@khalil111authorFeb 17.2017 — Right: https://yoocon.de/work/carrera-shop.php has lots of images.

But on my website will not have any images, I just want to achieve the arrow function
×

Success!

Help @khalil111 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...