Home > Enterprise >  Move to top on click of button
Move to top on click of button

Time:09-18

I am using intro.js in my code to implement the walkthrough. I want to implement a sceanrio where on clicking the done button(.introjs-donebutton) the page should scroll to the top but with this code It is not happening. Can anyone please help me with this one?

//$('.col-new-four').attr('id','essentials');
  const intro = introJs();
  
  intro.setOptions({
    steps:[
  {
      element:'#featured_apps_2_0',
      intro:'welcome'
    },
    {
      element:'#myTopnav',
      intro:'Quickly access the apps and portals you need on and off the clock.'
    },
    {
      element:'.slideshow-container',
      intro:'This space features topics you care about the most.'
    },
  {
  element:'.card',
  intro:'Stay up-to-date on trending stories.'
  },
  {
  element:'#stepextra',
  intro:'View your recommended and favorite pages.'
  },
  {
  element:'#step4',
  intro:'Find promotional content, latest additions and more here.'
  },
  {
  element:'#essentials2',
  intro:'Learn about what’s trending with your favorite topics.'
  },
  {
  element:'.col-new-7525',
  intro:'Explore benefits, tools and new features available to you.'
  }
    ]   
  })
  
  $('.introjs-donebutton').click(function() {
   $(window).scrollTop(0);
});
  
  function callintro(){
    intro.start();
    console.log("called intro")
  }
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/intro.js/4.2.2/intro.min.js"></script>

CodePudding user response:

I assume that you want to scroll the client view page to top on clicking a button. if so you can use this code

HTML

<div class="button-parent">
   <button type="button" class="button-to-top">Click Here</button>
</div>

jQuery

$(document).ready(function () {
    $('.button-to-top').on('click', function () {
        $('body').scrollTop(0);
    });
});

Don't Forget to add jQuery cdns to your html header file. If it's not working share your html code. we will look forward

CodePudding user response:

Using pure javascript, no framework

window.scrollTo({ top: 0, behavior: 'smooth' })

CodePudding user response:

So i used this and It started running fine, the reason being the button was dynamically being created after the inital page load, so this should work

  $(document).on("click", ".introjs-donebutton", function(){
    $(document).scrollTop(0);
  })
  • Related