CSS边框悬停动画

css border hover animations

本文关键字:动画 悬停 边框 CSS      更新时间:2023-09-26

我正在尝试悬停边界动画。但是我没有得到动画,

这是我的代码。你能帮帮我吗?

$(".divBox1").mouseover(function(){
        console.log('enter');
        $(this).animate({border: "3px solid #000"}, 100);
    }).mouseout(function(){
            console.log('out');
            $(this).animate({border: "3px solid #FFF55B"}, 100);
    });

试试这个,给border属性添加引号

$(".divBox1").mouseover(function(){
    //console.log('enter');
    $(this).animate({"border": "3px solid #000"}, 100);
}).mouseout(function(){
    //console.log('out');
    $(this).animate({"border": "3px solid #FFF55B"}, 100);
});

尝试将css border属性用双引号括起来

用CSS试试,这很简单

  .divBox1{
 border: 3px solid #FFF55B;
}
.divBox1:hover {
        border: 3px solid #000;
            -webkit-transition: all 0.25s ease-in-out;
            -moz-transition: all 0.25s ease-in-out;
            -o-transition: all 0.25s ease-in-out;
            -ms-transition: all 0.25s ease-in-out;
            transition: all 0.25s ease-in-out;
        }

你不能像这样为静态边界添加动画。你可以在css3中操作边框图像。

更多查询请参考此链接

还可以看看这个插件

您必须使用jQueryjQuery ui来表示animating colors。因为您的代码表明you just want to animate colors not the width,动画宽度可以通过

实现

borderWidth: '3px'

css:

.divBox1 {
   border:solid 3px #FFF55B;
}

脚本:

 <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <script src="http://code.jquery.com/ui/1.10.1/jquery-ui.js"></script>
 <script>
     $(function(){
         $(".divBox1").mouseover(function () {
             $(this).animate({borderColor: "#000"}, 800);
         }).mouseout(function () {
             $(this).animate({borderColor: "#FFF55B"}, 800);
         });
     });
 </script>

注意:

如果没有jquery ui,这将无法工作。

这是你想要的吗?

    $(".divBox1").css("border","3px solid transparent").mouseover(function(){
        //console.log('enter');
        $(this).animate({"border-color": '#000'}, 100);
    }).mouseout(function(){
        //console.log('out');
        $(this).animate({"border-color": "#FFF55B"}, 100);
    });
<标题>注意:你需要jQuery UI