Last active
August 29, 2015 14:13
-
-
Save klihelp/67798dfc1266c3684326 to your computer and use it in GitHub Desktop.
Kli-WebApp - Custom Cursor with HTML/JS/CSS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
// From Klihelp: | |
// https://gist.github.com/klihelp/67798dfc1266c3684326 | |
// | |
// The idea is that | |
// - we hide the real cursor | |
// - and #custom_cursor div will follow the cursor, inside this div can have any text or image | |
--> | |
<div class="main_area"> | |
... | |
... | |
... | |
</div> | |
<!-- | |
// The html: | |
--> | |
<div id="custom_cursor">HELLO</div> | |
<!-- | |
// The script uses jQuery | |
--> | |
<script type="text/javascript"> | |
$(document).ready(function(){ | |
var $area = $('.main_area').css({ | |
'cursor':'none' | |
}), | |
$myCursor = $('.custom_cursor').css({ | |
'position': 'fixed', | |
'z-index': '999' | |
}) | |
if ($myCursor.lenght){ | |
$area | |
.on('mouseout.customCursor', function(){ | |
$myCursor.hide() | |
}) | |
.on('mousemove.customCursor', function(event){ | |
$myCursor.show().css({ | |
'left': event.clientX - 20, | |
'top': event.clientY + 7 | |
}) | |
}) | |
} | |
}) | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment