0

I use bootstrap in my site and to explain my site I would like to use bootstrap tour. I have implement this in my test page and work fine. But the tour start when load the page, and I want starting a tour when click a button. I have follow this article to implement my bootstrap tour.

This is a javascript of the bootstrap tour demo:

(function(){

    var tour = new Tour({
        storage : false
    });

    tour.addSteps([
      {
        element: ".tour-step.tour-step-one",
        placement: "bottom",
        title: "Welcome to our landing page!",
        content: "This tour will guide you through some of the features we'd like to point out."
      },
      {
        element: ".tour-step.tour-step-two",
        placement: "bottom",
        title: "Main navigation",
        content: "Here are the sections of this page, easily laid out."
      },
      {
        element: ".tour-step.tour-step-three",
        placement: "top",
        backdrop: true,
        title: "Main section",
        content: "This is a section that you can read. It has valuable information."
      },

    ]);

    // Initialize the tour
    tour.init();

    // Start the tour
    tour.start();

}());

and this is the html section:

<div class="content-section-a tour-step tour-step-one"> One <br>

<div class="content-section-a tour-step tour-step-two"> Two <br>

<div class="content-section-a tour-step tour-step-three"> Three <br>

How to start my tour by click a button?

Thanks

Frankie
  • 490
  • 8
  • 23

3 Answers3

0

Simply call tour.start(); when you click the button, and not on page load. Assuming your startbutton has the id start-tour. This snippet can be placed within (function() { ... })

$("#start-tour").click(function() {
    tour.start();
});
Script_Coded
  • 709
  • 8
  • 21
0

just change it to restart and it works.

$("#start-tour").click(function() { tour.restart(); });

Sheghzo
  • 26
  • 5
0

first we write our operations to a function. Here it is important to write the definition of the tour outside the function.

var tour = new Tour();    

  function StartTour(){
      tour = new Tour({
        storage : false
      });

    tour.addSteps([
      {
        element: ".tour-step.tour-step-one",
        placement: "bottom",
        title: "Welcome to our landing page!",
        content: "This tour will guide you through some of the features we'd like to point out."
      },
      {
        element: ".tour-step.tour-step-two",
        placement: "bottom",
        title: "Main navigation",
        content: "Here are the sections of this page, easily laid out."
      },
      {
        element: ".tour-step.tour-step-three",
        placement: "top",
        backdrop: true,
        title: "Main section",
        content: "This is a section that you can read. It has valuable information."
      },

    ]);

    // Initialize the tour
    tour.init();

    // Start the tour
    tour.start(true);
}

Then we call StartTour function in the button click function.

  $(".tour-step").click(function() {
    StartTour(); 
   });