简体   繁体   English

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

[英]How to use box-shadow with jQuery animate()?

I have a an li element which needs to animate to box shadow on hover but I am not able to get the desired results here is my javascript code: 我有一个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();
})
});

Thankyou 谢谢

Direct answer 直接回答

Using Edwin Martin's jQuery plugin for shadow animation , which extends the .animate method, you can simply use the normal syntax with "boxShadow" and every facet of that - color , the x- and y-offset , the blur-radius and spread-radius - gets animated. 使用埃德温·马丁(Edwin Martin)的用于阴影动画jQuery插件(扩展了.animate方法),您可以简单地将常规语法与“ boxShadow”配合使用,并使用其各个方面- 颜色x和y偏移模糊半径散布- radius-获取动画。 It includes multiple shadow support. 它包括多个阴影支持。

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

Using CSS 使用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); 
}

Add this in your css and add it wherever you want 将此添加到您的CSS中,然后将其添加到任意位置

 body{ background: #fff; } .box { transition: box-shadow .3s; width: 300px; height: 500px; margin: 50px; border-radius:10px; border: 1px solid #ccc; background: #fff; float: left; } .box:hover { box-shadow: 0 0 11px rgba(33,33,33,.2); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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