gpt4 book ai didi

jquery - 使用剪辑路径在 div 上平滑动画

转载 作者:太空宇宙 更新时间:2023-11-04 09:39:39 25 4
gpt4 key购买 nike

我想在元素滑入的悬停时实现平滑的动画,该元素使用 clip-path 进行剪辑但是当它滑入时它看起来都是锯齿状的直到它到达最终位置,有没有办法不看起来参差不齐?或者使用类似的简单代码的更好解决方案?代码和 JSFiddle:

https://jsfiddle.net/4bcvydpu/

HTML

<html>
<body>

<div class ="mainCard">

<div class="topEntrance fadeInDown">
</div>

</div><!--mainCard-->

</body>
</html>

CSS

.mainCard {
background-color: blue;
height: 500px;
width: 400px;
}

.topEntrance {
background-color: black;
height: 200px;
width: 400px;
-webkit-clip-path: polygon(0% 0%, 100% 0%, 100% 100%, 0% 35%);
color: white;
}

Javascript

$(".topEntrance").hide();

$(".mainCard").on('mouseenter', function() {
$(".topEntrance").animate({
width: "toggle"
})
});


$(".mainCard").on('mouseleave', function() {
$(".topEntrance").animate({
width: "toggle"
})
})

最佳答案

您可以在没有 javascript 的情况下仅使用 CSS 来做到这一点。

首先删除您的 javascript,然后将此更改添加到您的 CSS:

.mainCard {
background-color: blue;
height: 500px;
width: 400px;
overflow:hidden;
}

.topEntrance {
background-color: black;
height: 200px;
width: 400px;
-webkit-clip-path: polygon(100% 100%, 100% 0, 0 0, 0 35%);
color: white;
position:relative;
left:-100%;
-webkit-transition: all 0.4s ease;
}

.mainCard:hover .topEntrance{
left:0;
}

关于jquery - 使用剪辑路径在 div 上平滑动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40042336/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com