jquery - 用于文本颜色和移动文本的 css 动画,带有 jquery 示例

标签 jquery css animation css-transitions

我正在尝试为我的文本颜色设置动画,并在悬停文本后向右移动约 15 像素。我认为这可以通过 css 实现,但不确定从哪里开始。

$('#home_solutions_list li').mouseenter(function() {
  link = $(this).find('.home_view_products a');
  link.stop(true, true).animate({
   'color': '#636a6d'
  }, 'fast');
  link.find('span').animate({
   'padding-left': '20px'
   }, 'fast');
});

所以颜色应该改变(不工作 jsfiddle),然后 span 元素应该移动到文本的右侧。但是只有 span 元素应该移动,当前文本居中,链接文本也在移动。这可以简单地在 css 中完成吗?

http://jsfiddle.net/Q8KVC/2278/

最佳答案

设置这个:

.home_view_products a span {
  font-size: 16px;
  padding: 5px;
  position: relative;
  left: 0;
}

并将您的 JS 更改为:

$('#home_solutions_list li').mouseenter(function() {
  link = $(this).find('.home_view_products a');
  link.stop(true, true).animate({
    'color': '#636a6d'
  }, 'fast');
  link.find('span').animate({
    'left': '20px',
  }, 'fast');
});
$('#home_solutions_list li').mouseleave(function() {
  link = $(this).find('.home_view_products a');
  link.stop(true, true).animate({
    'color': '#1a92d0'
  }, 'fast');
  link.find('span').animate({
    'left': '5px'
  }, 'fast');
});

但是,我建议为悬停和悬停创建一个类,并使用 CSS 选择器而不是任何 JS 来设置这些类。只是一个小提示。

关于jquery - 用于文本颜色和移动文本的 css 动画,带有 jquery 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42754890/

相关文章:

javascript - href 始终为 "undefined"

css - ttf2eot - Mac OS X 上的输入路径是什么?

javascript - 当垂直滚动到某个点时移动图像

jquery - Chart.js 图例样式

java - float 操作按钮上的淡入淡出动画

附加 html 时的 jquery 动画

javascript - 检测特定属性的可用 css 值

jquery - Chrome 扩展程序 XHR 不起作用

javascript - 在 TinyMCE 中初始化后修改工具栏的正确方法

css - 样式表对 html 没有影响(但 Bootstrap 样式有效)