手风琴需要在打开Javascript时滚动到顶部

时间:2016-07-18 17:11:02

标签: javascript accordion scrollto

我熟悉jQuery,但对Javascript并不熟悉。我在javascript中有一个手风琴功能,我需要手风琴面板在点击时滚动到打开面板的顶部。现在它在打开时滚动到面板的底部。这是我正在使用的点击功能...提前致谢!

myAPP.AccordionPanel = function ( headingEl, panelHolder, index ) {
// The AccordionPanel Class controls each of the collapsable panels spawned from Accordion Class
var self = this;

this.panelHolder = panelHolder;
this.index = index;
this.headingEl = headingEl; // this is the clickable heading
this.contentEl = headingEl.nextElementSibling;//headingEl.querySelector( this.panelHolder.panelSelectors['content'] ); 
this.isSelected = false;

this.setupAccessibility();

this.headingEl.addEventListener( "click", function () {

    if (self.isSelected){
        self.unselect(); // already open, presume user wants it closed
    }
    else {
        self.panelHolder.resetPanels(); // close all panels
        self.select(); // then open desired panel        
    }

    return false;
});

return this;

};

1 个答案:

答案 0 :(得分:0)

您可以访问要单击的元素,可以调用下面的函数滚动到它。如果你点击的东西不是那个,你需要一个参考。

从这里解放的功能 - http://itnewb.com/tutorial/Creating-the-Smooth-Scroll-Effect-with-JavaScript

  onclick(event)
  {
     this._cr.resolveComponent(Loader).then(cmpFactory => {
          if(this.cmpRef) {
            this.cmpRef.destroy();
            this.cmpRef = null;
          }
          console.log("Creating component");

          //this.childContainer.createComponent(cmpFactory,null, this._injector);
          this.cmpRef = this.childContainer.createComponent(cmpFactory);
          this.cmpRef.instance.ParentID = "55";  

      });

  }