forked from rebillar/site-accueil-insa
curseur update on scroll
This commit is contained in:
parent
b5b53572ed
commit
f0b9280729
1 changed files with 44 additions and 16 deletions
|
@ -1,23 +1,51 @@
|
|||
<script type="text/javascript">
|
||||
document.onmousemove = suitsouris;
|
||||
function suitsouris(evenement)
|
||||
{
|
||||
if(navigator.appName=="Microsoft Internet Explorer")
|
||||
{
|
||||
var x = event.x+document.body.scrollLeft;
|
||||
var y = event.y+document.body.scrollTop;
|
||||
}
|
||||
else
|
||||
{
|
||||
var x = evenement.pageX;
|
||||
var y = evenement.pageY;
|
||||
}
|
||||
document.getElementById("image_suit_souris").style.left = (x+1/*+1-43*/)+'px';
|
||||
document.getElementById("image_suit_souris").style.top = (y+1/*-17*/)+'px';
|
||||
}
|
||||
|
||||
/** les variables x/y MousePos contiennent les coordonnés de la souris */
|
||||
var xMousePos = 0;
|
||||
var yMousePos = 0;
|
||||
|
||||
/** stockent des informations sur le dernier scroll (pour update le positionnement de la souris) */
|
||||
var lastScrolledLeft = 0;
|
||||
var lastScrolledTop = 0;
|
||||
|
||||
addEventListener("mousemove", (ev) => {
|
||||
|
||||
if(navigator.appName=="Microsoft Internet Explorer") {
|
||||
xMousePos = event.x+document.body.scrollLeft;
|
||||
yMousePos = event.y+document.body.scrollTop;
|
||||
} else {
|
||||
xMousePos = ev.pageX;
|
||||
yMousePos = ev.pageY;
|
||||
}
|
||||
|
||||
document.getElementById("image_suit_souris").style.left = (xMousePos+1/*+1-43*/)+'px';
|
||||
document.getElementById("image_suit_souris").style.top = (yMousePos+1/*-17*/)+'px';
|
||||
})
|
||||
|
||||
addEventListener("scroll", (ev) => {
|
||||
if(lastScrolledLeft !== document.scrollingElement.scrollLeft){
|
||||
xMousePos -= lastScrolledLeft;
|
||||
lastScrolledLeft = document.scrollingElement.scrollLeft;
|
||||
xMousePos += lastScrolledLeft;
|
||||
}
|
||||
if(lastScrolledTop !== document.scrollingElement.scrollTop){
|
||||
yMousePos -= lastScrolledTop;
|
||||
lastScrolledTop = document.scrollingElement.scrollTop;
|
||||
yMousePos += lastScrolledTop;
|
||||
}
|
||||
|
||||
document.getElementById("image_suit_souris").style.left = (xMousePos+1/*+1-43*/)+'px';
|
||||
document.getElementById("image_suit_souris").style.top = (yMousePos+1/*-17*/)+'px';
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
body {
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
.cursor {
|
||||
position: absolute;
|
||||
display: block;
|
||||
|
|
Loading…
Reference in a new issue