2017-06-02 64 views
0

目前,我在主頁上有不同的行,每行都有一個按鈕。點擊按鈕後,div將滑動到頁面的頂部。但與此同時,還有另一個操作添加到按鈕。下面是我的js代碼:Onclick slide to current div

$(".expandable-container-mobile").click(function() { 

      var el = $(this).find('.mobile-show-section');//get the current element 
      var el2 = $(this).find('.expandable'); 

      el.stop().slideToggle(700);//toggle the current one 
      $(this).children('.expandable').toggleClass('clicked'); 


      $('.expandable').not(el2).removeClass('clicked'); 
      $('.mobile-show-section').not(el).stop().slideUp();//hide the rest 

     }); 

我使用scrollify JS $ .scrollify.move( 「#名字」);但它似乎沒有與div-section-name一起工作,其他方式來實現它也很好。

+0

安置自己的HTML以及所以我們有一個更好的想法是什麼你正在努力 –

回答

0

使用jQuery,一塊代碼 -

function scrollToAnchor(aid){ 
    //get the element to be scrolled 
    var el = $(this).find('.mobile-show-section'); 
    //then scroll it using jQuery annimation 
    $('html,body').animate({scrollTop: el.offset().top},500); 
    }; 

見我的一些回答,

Answer1

Answer2