javascript - jQuery 动画总是以相同的速度

标签 javascript jquery html css animation

我想更改我的 jQuery 动画的速度,以便它始终保持相同的速度。我有 4 个 div,它们为 mouseenter 上的背景图像位置设置动画。我现在看到动画总是有不同的速度,它总是需要 2500 毫秒。我希望速度始终相同,这怎么可能?

HTML:

<div id="imgholder">
<div class="imggridcol" id="linksboven"></div>
<div class="imggridcol" id="rechtsboven"></div>
<div class="imggridcol" id="linksonder"></div>
<div class="imggridcol" id="rechtsonder"></div>
</div>

CSS:

#imgholder {
width:960px;
height:380px;
overflow:hidden;
background: url("http://crispme.com/wp-content/uploads/4379.jpg?pass") no-repeat;
background-position:50% 50%;
background-size:150% 150%;
}

.imggridcol {
width:50%;
height:50%;
margin:0px;
float:left;
}

jQuery:

$("#linksboven").mouseenter(function() {
  $(this).parent().stop().animate({
  backgroundPositionX: '0%',
  backgroundPositionY: '0%'
  }, 2500, "linear");
});

$("#rechtsboven").mouseenter(function() {
  $(this).parent().stop().animate({
  backgroundPositionX: '100%',
  backgroundPositionY: '0%'
  }, 2500, "linear");
});

$("#linksonder").mouseenter(function() {
  $(this).parent().stop().animate({
  backgroundPositionX: '0%',
  backgroundPositionY: '100%'
  }, 2500, "linear");
});


$("#rechtsonder").mouseenter(function() {
  $(this).parent().stop().animate({
  backgroundPositionX: '100%',
  backgroundPositionY: '100%'
  }, 2500, "linear");
});

$(".imggridcol").mouseleave(function() {
 $(this).parent().stop();   
});

JSFiddle demo

最佳答案

http://lukeshumard.github.io/supremation/

根据我的评论,这实际上似乎是答案。这个 jQuery 插件应该有帮助。只需调用,例如:


$("#linksboven").mouseenter(function() {
      $(this).parent().stop().supremate({
      backgroundPositionX: '0%',
      backgroundPositionY: '0%'
      }, 2500, "linear");
});

代替 animate 函数,它将处理其余部分

关于javascript - jQuery 动画总是以相同的速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22018095/

相关文章:

javascript - 将innerHTML 抓取到变量中

javascript - 必填字段验证器不适用于 JQuery 选择的下拉列表

javascript - 替换字符串,除非它在给定字符串的某个子字符串中

javascript - ScrollTop 在 IE 中不起作用

javascript - 类型错误 : Cannot read property 'client_secret' of undefined

javascript - 用于信用卡检测的 RegEx 和 Keyup

html - Owl Carousel : first slide not trigger action

html - 片段链接失效

javascript - CSS 不适用于表格以及如何在 innerHTML 中关联多个标签

jquery - 如何设置数据表的总页数