简体   繁体   English

垂直居中jQuery手风琴

[英]Vertically Center jQuery Accordion

I used this script to create a jQuery accordion. 我用这个脚本创建了一个jQuery手风琴。 Check out the working jsFiddle here . 在这里查看工作jsFiddle

It works great, except I would like the accordion to be vertically centered on the page. 它很棒,除了我希望手风琴在页面上垂直居中。 The idea is that as the height of the accordion changes the DIV would be constantly realigned to be vertically centered. 这个想法是,随着手风琴高度的变化, DIV将不断地重新排列成垂直居中。 The accordion would appear to expand from the center of the page, rather then sliding down from the top. 手风琴似乎从页面中心扩展,而不是从顶部向下滑动。

You can write a method which will center the accordion container and call this method whenever sliding animation is complete as per your logic. 您可以编写一个方法,该方法将手风琴容器居中,并根据您的逻辑在滑动动画完成时调用此方法。

function centerIt(){
    var $accordion = $('.accordion');
    $accordion.css('top', ($(window).height() - $accordion.height())/2);
}

Working demo - http://jsfiddle.net/hDRMP/6/ 工作演示 - http://jsfiddle.net/hDRMP/6/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM