简体   繁体   中英

Onclick slide to current div

Currently, I have various rows on the homepage, and each row has a button. When the button is clicked, the div will slide up to the top of the page. But meanwhile, there is another action added to the button as well. Below is my js code:

$( ".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

        });

I am using scrollify js $.scrollify.move("#name"); but it doesn't seem to work with the div-section-name, other way to achieve it is fine as well.

Use jQuery, piece of code-

 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);
  };

See some of my answers,

Answer1

Answer2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM