Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 点击按钮向下滚动角度6中的div(直到底部)?_Angular_Scroll - Fatal编程技术网

Angular 点击按钮向下滚动角度6中的div(直到底部)?

Angular 点击按钮向下滚动角度6中的div(直到底部)?,angular,scroll,Angular,Scroll,我参考了这个链接(NPM:@nicky lenaers/ngx滚动到)和这么多答案,但我没有得到完美的解决方案。当我点击按钮时,我的div页面(div高度可能不是固定的),它只是向下滚动一点点,但我想让页面向下滚动到底部。建议的任何其他解决方案或修改。多谢各位 chat.component.html <div id="destination"> My Content is here</div> <button (click)="getChatMessages()"&

我参考了这个链接(NPM:@nicky lenaers/ngx滚动到)和这么多答案,但我没有得到完美的解决方案。当我点击按钮时,我的div页面(div高度可能不是固定的),它只是向下滚动一点点,但我想让页面向下滚动到底部。建议的任何其他解决方案或修改。多谢各位

chat.component.html

<div id="destination"> My Content is here</div>
<button (click)="getChatMessages()">SAVE</button> 
我的内容在这里
最后,在结束你的div之前做一个小div。

我的内容在这里

在结束你的div之前,在最后做一个小div。

在这方面做了很多尝试。在我的情况下,没有任何图书馆能帮上忙

所以你可以试试我用的

_onButtonClick (e) {

        this._pageY = e.pageY;

        if (true) {
          //scroll while drag
          const y = this._pageY;
          const container =  <HTMLElement>document.querySelector('.yourcontainerclass');
          const containerBottom =  container.offsetTop + container.offsetHeight;
          const containerTop =  container.offsetTop;
          if (containerBottom - y < 120) { // To leave a space and scroll down
            container.scrollTop += containerBottom - 30;
          } else if (containerTop + y < 250) { // you do not need this but if you have a button on top,you may want to scroll up

            container.scrollTop -= containerTop + 30;
          }
        }
      }
\u on按钮单击(e){
这个;
如果(真){
//拖动时滚动
常数y=这个;
const container=document.querySelector('.yourcontainerclass');
const containerBottom=container.offsetTop+container.offsetHeight;
const containerTop=container.offsetTop;
if(containerBottom-y<120){//留下一个空格并向下滚动
container.scrollTop+=containerBottom-30;
}否则,如果(containerTop+y<250){//您不需要这个,但是如果您在顶部有一个按钮,您可能需要向上滚动
container.scrollTop-=containerTop+30;
}
}
}

将此添加到按钮上,如
onclick=\u onButtonClick($event)

对此做了很多尝试。在我的情况下,没有任何图书馆能帮上忙

所以你可以试试我用的

_onButtonClick (e) {

        this._pageY = e.pageY;

        if (true) {
          //scroll while drag
          const y = this._pageY;
          const container =  <HTMLElement>document.querySelector('.yourcontainerclass');
          const containerBottom =  container.offsetTop + container.offsetHeight;
          const containerTop =  container.offsetTop;
          if (containerBottom - y < 120) { // To leave a space and scroll down
            container.scrollTop += containerBottom - 30;
          } else if (containerTop + y < 250) { // you do not need this but if you have a button on top,you may want to scroll up

            container.scrollTop -= containerTop + 30;
          }
        }
      }
\u on按钮单击(e){
这个;
如果(真){
//拖动时滚动
常数y=这个;
const container=document.querySelector('.yourcontainerclass');
const containerBottom=container.offsetTop+container.offsetHeight;
const containerTop=container.offsetTop;
if(containerBottom-y<120){//留下一个空格并向下滚动
container.scrollTop+=containerBottom-30;
}否则,如果(containerTop+y<250){//您不需要这个,但是如果您在顶部有一个按钮,您可能需要向上滚动
container.scrollTop-=containerTop+30;
}
}
}

在您的按钮上添加此选项,如
onclick=\u onButtonClick($event)

Asanka关闭div之前我做的这不起作用您是否从父div中删除id=“destination”?是的,我从父div中删除它现在会滚动多一点,但不会滚动到底OK。你要做的是把这个->放在你想要滚动的页面中。我已经放了一个例子,你可以看到。如果我在关闭div之前做的不起作用,你会从父div中删除id=“destination”吗?是的,我会从父div中删除它,现在它会滚动多一点,但不会滚动到底OK。你想要的是把这个->放在你想要滚动的页面中。我已经把你可以看到的例子放在这里。你可以在这里找到定义。如果出现错误,请检查htmlelement是否从dom@user10411207如果将“.yourcontainerclass”替换为一个真正的选择器,则可以消除OffsetTop错误。您可以在此处找到定义。如果出现错误,请检查htmlelement是否从dom@user10411207如果用一个真正的选择器替换“.yourcontainerclass”,您将摆脱Offsettop错误。