开发者

jQuery animate not working in chrome/safari/ie

开发者 https://www.devze.com 2023-01-16 05:05 出处:网络
I have written a few lines of jQuery to animate a div to the left/right depending on mouse movements $(\".galleryNav\").mousemove(function(e){

I have written a few lines of jQuery to animate a div to the left/right depending on mouse movements

 $(".galleryNav").mousemove(function(e){
  $("#status").html(e.pageX +', '+e.pageY);

  if(e.pageX > 1100 && e.pageX < 1170){
   $(".galleryNav").animate({marginLeft:"-60px"},{queue: false, duration: 450});
  }

  if(e.pageX > 410 && 开发者_如何学编程e.pageX < 465){
   $(".galleryNav").animate({marginLeft:"10px"},{queue: false, duration: 450});
  }
 });

it works fine in firefox, but nothing happens in chrome, safari or IE.

Any suggestions?


I had exactly this problem...the div that I was animating had position:absolute. What fixed it for me was setting the top and left in the css. Once I added them bingo it worked!


To me it works fine withe jQuery 1.4.2 + UI 8. Check you CSS.


Works fine in chrome http://jsfiddle.net/x9eZY/ maybe the problem is elsewhere? have you encapsulated your script in $(function(){}) like so:

$(function(){
    $(".galleryNav").mousemove(function(e){
      $("#status").html(e.pageX +', '+e.pageY);

      if(e.pageX > 1100 && e.pageX < 1170){
       $(".galleryNav").animate({marginLeft:"-60px"},{queue: false, duration: 450});
      }

      if(e.pageX > 410 && e.pageX < 465){
       $(".galleryNav").animate({marginLeft:"10px"},{queue: false, duration: 450});
      }
    });
})  
​
0

精彩评论

暂无评论...
验证码 换一张
取 消