当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Div with scroll bar - Scroll to top using scrollTop()

问题描述:

How do I scroll to the top of #studentName?

I've used css to #studentName. So the scroller bar appears after 100px. So What I need is to be able to go to the top level of #studentName when goTop() is triggered.

css:

#studentName{

overflow-y: scroll;

max-height: 100px;

}

This is what I've tried. (did not scroll)

function goTOP(){

$('#studentName').animate({ 'scrollTop': 0 }, 100);

}

网友答案:

just remove the quotes and it should work.

function goTOP(){
  $('#studentName').animate({ scrollTop: 0 }, 100); 
}
网友答案:

You are scrolling to 0px in 100ms

$( "#studentName" ).scrollTop(0)

This function depends on you jQuery version....

分享给朋友:
您可能感兴趣的文章:
随机阅读: