jquery菜单滑动及显示隐藏效果

滑动效果

$(document).ready(function () {
    $(".menu_body").hide();

    $(".menu_head").click(function () {
        //通过next(".menu_body") 获得对应的内容DIV,让其具有“滑动”效果  
        // 再通过siblings(".menu_body")获得所有同级的 内容DIV, 让其滑动着隐藏起来, (同一时间,只有一个内容DIV显示出来)  
    $(this).next(".menu_body").slideDown("slow").siblings(".menu_body").hide();
    });
}); 


隐藏显示效果

$(document).ready(function(){
$("#barImg").toggle(function(){
$(".menu").hide();
$("#barImg").attr("src","images/butOpen.gif")},function(){
$(".menu").show();
$("#barImg").attr("src","images/butClose.gif")
});
});


 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是一个简单的jQuery代码,可以实现类似腾讯云的滑动下拉导航菜单效果: HTML代码: ```html <div class="dropdown"> <button class="dropbtn">菜单</button> <div class="dropdown-content"> <a href="#">链接1</a> <a href="#">链接2</a> <a href="#">链接3</a> </div> </div> ``` CSS样式: ```css .dropdown { position: relative; display: inline-block; } .dropdown-content { display: none; position: absolute; z-index: 1; } .dropdown-content a { display: block; text-align: left; } .dropdown:hover .dropdown-content { display: block; } .dropbtn { background-color: #4CAF50; color: white; padding: 16px; font-size: 16px; border: none; cursor: pointer; } .dropbtn:hover { background-color: #3e8e41; } ``` jQuery代码: ```javascript $(document).ready(function() { $(".dropdown").hover(function() { $(this).children(".dropdown-content").slideDown("fast"); }, function() { $(this).children(".dropdown-content").slideUp("fast"); }); }); ``` 代码解释: - 首先,在HTML中创建一个包含菜单按钮和下拉内容的元素。 - 用CSS样式设置菜单按钮和下拉内容的样式。 - 使用jQuery代码设置当鼠标悬停在菜单按钮上时,下拉内容被显示出来。当鼠标移开时,下拉内容又被隐藏起来。具体实现是通过jQuery的`hover()`方法来完成的,方法的第一个参数是当鼠标进入时要执行的函数,第二个参数是当鼠标移出时要执行的函数。在这里,我们使用`slideDown()`和`slideUp()`方法来实现下拉和隐藏效果,其中`"fast"`表示动画的速度,也可以使用其他值或者自定义速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值