forked from vergnet/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">
|
<script type="text/javascript">
|
||||||
document.onmousemove = suitsouris;
|
|
||||||
function suitsouris(evenement)
|
/** les variables x/y MousePos contiennent les coordonnés de la souris */
|
||||||
{
|
var xMousePos = 0;
|
||||||
if(navigator.appName=="Microsoft Internet Explorer")
|
var yMousePos = 0;
|
||||||
{
|
|
||||||
var x = event.x+document.body.scrollLeft;
|
/** stockent des informations sur le dernier scroll (pour update le positionnement de la souris) */
|
||||||
var y = event.y+document.body.scrollTop;
|
var lastScrolledLeft = 0;
|
||||||
}
|
var lastScrolledTop = 0;
|
||||||
else
|
|
||||||
{
|
addEventListener("mousemove", (ev) => {
|
||||||
var x = evenement.pageX;
|
|
||||||
var y = evenement.pageY;
|
if(navigator.appName=="Microsoft Internet Explorer") {
|
||||||
}
|
xMousePos = event.x+document.body.scrollLeft;
|
||||||
document.getElementById("image_suit_souris").style.left = (x+1/*+1-43*/)+'px';
|
yMousePos = event.y+document.body.scrollTop;
|
||||||
document.getElementById("image_suit_souris").style.top = (y+1/*-17*/)+'px';
|
} 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>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|
||||||
|
body {
|
||||||
|
overflow-x: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.cursor {
|
.cursor {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
display: block;
|
display: block;
|
||||||
|
|
Loading…
Reference in a new issue