简体   繁体   中英

In IE Some of the JS, Jquery codes are not working at start but after refreshing page 2-3 times. Any idea?

In IE Some of the JS, Jquery codes are not working at start but after refreshing page 2-3 times. Any idea? here is my code :

var  mouseY = 0;
$(document).mousemove(function(e){
mouseX = e.pageX;
mouseY = e.pageY; 
});


var follower = $("#follower");
var follower_2 = $("#follower_2");
var xp = 0, yp = 0;
var loop = setInterval(function()

{if((mouseY - yp >200 || yp - mouseY >250)||(( mouseX - xp >530 || mouseX - xp <280)&&( mouseX - xp <1370 || mouseX - xp >1620) )){






yp += (mouseY - yp) / 10;
follower.css({ top:yp-200 + 'px'});
follower_2.css({ top:yp-565 + 'px'});
}}, 25);

});

Put your code inside : $().ready() function and make your mouseX global varibale.

$(document).ready(function(){

var  mouseY = 0,mouseX=0;
$(document).mousemove(function(e){
mouseX = e.pageX;
 mouseY = e.pageY; 
});


 var follower = $("#follower");
 var follower_2 = $("#follower_2");
 var xp = 0, yp = 0;
 var loop = setInterval(function()

 {if((mouseY - yp >200 || yp - mouseY >250)||(( mouseX - xp >530 || mouseX - xp <280)&&( mouseX - xp <1370 || mouseX - xp >1620) )){


yp += (mouseY - yp) / 10;
 follower.css({ top:yp-200 + 'px'});
 follower_2.css({ top:yp-565 + 'px'});
 }}, 25);

 });

 })

Provide your fiddle for better answering.

May this helps you..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM