javascript - 如何在 jQuery animate() 中使用 box-shadow?

标签 javascript jquery html css box-shadow

我有一个 li 元素,它需要在悬停时为框阴影设置动画,但我无法在此处获得所需的结果,这是我的 javascript 代码:

$(document).ready(function () {
$('#skill_list li').hover(function () {
    $(this).animate({
        top: "-5px",
        boxShadow: "10px 10px red"
    }, 100, "linear").clearQueue();
}, function () {
    $(this).animate({
        top: "0px",
        boxShadow:"0px 0px"
    }, 100, "linear").clearQueue();
})
});

谢谢

最佳答案

直接回答

使用 Edwin Martin 的 jQuery plugin for shadow animation ,它扩展了 .animate 方法,您可以简单地使用带有“boxShadow”的普通语法和它的每个方面 - colorx - 和 y 偏移量模糊半径展开半径 - 被动画化。它包括多个阴影支持。

$(element).animate({ 
  boxShadow: "0px 0px 5px 3px hsla(100, 70%, 60%, 0.8)"
}); 

使用 CSS

.element{
  transition: all 0.8s ease-in;
  width: 50px;
  height: 50px;
  border: 1px solid black;
}
.element:hover {
  box-shadow: 0px 0px 5px 3px hsla(100, 70%, 60%, 0.8); 
}

关于javascript - 如何在 jQuery animate() 中使用 box-shadow?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50140225/

相关文章:

javascript - AngularJS 更新服务变量不起作用

javascript - 如何在javascript中将拖放区域的宽度调整为100%

javascript - 链接 anchor 文本以打开特定选项卡

javascript - 如何抽象 JQuery 动画方法

javascript - 如何向 YouTrack 工作流程中的某些操作添加基于组或角色的限制?

javascript 关闭 : implicit parameters, 调用者

javascript - 如何使 TypeScript 输出有效的 ES6 模块导入语句?

javascript - 根据复选框 ID 值填充输入字段

jquery - 在 tr 之前添加行不起作用

html - 将鼠标悬停在另一个容器上时显示 DIV 容器