jQuery滚动引导面板到屏幕顶部不起作用

时间:2014-02-09 01:09:55

标签: jquery twitter-bootstrap

我有一个小的jquery脚本无法运行&我不知道为什么

脚本:

$('#accordion-data-parent-001, #accordion-data-parent-002').on('shown.bs.collapse', function (e) {
   var id = $(e.target).prev().find("[id]")[0].id;
   navigateToElement(id);
})

function navigateToElement(id) {
    $('html, body').animate({
        scrollTop: $("#" + id).offset().top -90
    }, 100);
}

HTML:

<div class="row">
    <div class="col-sm-6">
        <div class="panel-group" id="accordion-data-parent-001">
            <div class="panel panel-default"> <a data-toggle="collapse" data-parent="#accordion-data-parent-001, #accordion-data-parent-002" href="#collapse-37" class="staff">
                <div class="panel-heading" >
                    <div class="row">
                        <div class="col-sm-3"> <img class="img-responsive" src="assets/images/barak-obama.jpg" alt="" /> </div>
                        <div class="col-sm-9">
                            <h4 class="panel-title"> President Barak Obama </h4>
                        </div>
                    </div>
                </div>
                </a>
                <div id="collapse-37" class="panel-collapse collapse">
                    <div class="panel-body">
                        <p></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="col-sm-6">
        <div class="panel-group" id="accordion-data-parent-002">
            <div class="panel panel-default"> <a data-toggle="collapse" data-parent="#accordion-data-parent-001, #accordion-data-parent-002" href="#collapse-45" class="staff">
                <div class="panel-heading" >
                    <div class="row">
                        <div class="col-sm-3"> <img class="img-responsive" src="assets/images/clint-eastwood.jpg" alt="" /> </div>
                        <div class="col-sm-9">
                            <h4 class="panel-title"> A new guy </h4>
                        </div>
                    </div>
                </div>
                </a>
                <div id="collapse-45" class="panel-collapse collapse">
                    <div class="panel-body">
                        <p></p>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

应该将当前面板滚动到屏幕顶部,但我似乎无法使其正常工作。

0 个答案:

没有答案