可以使用jQuery的hover事件来触发slidetoggle效果。
例如,以下代码会在鼠标悬停在元素上时触发slidetoggle效果:
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function(){
$("#toggle").hover(function(){
$("#content").slideToggle();
});
});
</script>
<style>
#content {
display: none;
}
</style>
</head>
<body>
<div id="toggle">Hover over me</div>
<div id="content">This content will be toggled</div>
</body>
</html>
在这个例子中,当鼠标悬停在id为"toggle"的元素上时,会触发id为"content"的元素的slidetoggle效果。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读:text-decoration如何配合hover使用