JQuery Easing插件

时间:2012-12-04 09:58:00

标签: jquery easing

我想使用JQuery缓动来导航到我页面中的命名部分,到目前为止它都有效。

在其中一个部分中,我有一个表格,我想垂直和水平居中,所以我将它放在一个子div中,并垂直/水平居中。

我不确定该怎么做才能更改javascript,以便在跳转到表单部分时,表单可以轻松到页面中间。

我正在使用以下代码块:

$('.nav a').bind('click',function(event){

    var $anchor = $(this);

    $('html, body').stop().animate({
        scrollTop: $($anchor.attr('href')).offset().top
    }, 1500,'easeInOutExpo');

    event.preventDefault();
});    
       ​

这是我所拥有的JSFiddle,有谁可以赐教我?谢谢!

http://jsfiddle.net/soraya_soch/LyDWH/

[编辑]

我的目标是点击链接,页面缓和并停止表单的div。 enter image description here

1 个答案:

答案 0 :(得分:0)

检查一下,它没有将表格div设置为垂直居中,这有助于实现如上图所示设置所需的输出,因为还没有给出垂直中心

http://jsfiddle.net/LyDWH/3/

对CSS和HTML页面进行了微小的更改

div.cn {
    display: table-cell;
    width: 960px;
    height: 2000px;
    background: gray;
    text-align: center;
}

div.inner {
    display: inline-block;
    width: 200px;
    height: 200px;
    background: red;
    margin-top: 20%;
}
​
相关问题