将手风琴滑动到浏览器顶部

Slide accordion to browser top

本文关键字:浏览器 顶部 手风琴      更新时间:2024-02-16

我有一个内容很长的手风琴菜单。所以我需要在打开手风琴内容时实现幻灯片效果。

目前,如果打开前两个菜单项,那么最后一个菜单项将显示视口下方的内容,因此我需要为手风琴菜单项提供向上滑动的效果。

这是我的代码

$(document).ready(function () {
    //Accordion
    $(".menu_body").hide();
    //toggle the componenet with class menu_body
    $(".menu_head").click(function(){
        $(this).next(".menu_body").slideToggle(400); 
        var plusmin;
        plusmin = $(this).children(".plusminus").text();
        $(this).children("span.down-arrow").toggleClass("up-arrow");        
    });
});

DEMO

看看这个,这是预期的吗?

$(document).ready(function () {
    //Accordion
    $(".menu_body").hide();
    //toggle the componenet with class menu_body
    $(".menu_head").click(function(){
      $(".menu_body").each(function (event){
        $(".menu_body").hide();
      });
        $(this).next(".menu_body").slideToggle(400); 
        var plusmin;
        plusmin = $(this).children(".plusminus").text();
        $(this).children("span.down-arrow").toggleClass("up-arrow");        
    });
    });