mvc-tour.html appweb,Tourguide.js 一个简单,轻便,干净且小巧的库,用于为您的Web应用程序创建引导式产品导览...

Tourguide.js

Simple, lightweight library for creating guided tours for your web, apps and more.

A tour guide is a person who provides assistance, information on cultural, historical and contemporary heritage to people on organized tours and individual clients at educational establishments, religious and historical sites, museums, and at venues of other significant interest, attractions sites. [https://en.wikipedia.org/wiki/Tour_guide]

Fiddle with It

Want to see how it works right away? Try on JSFiddle

Install Tourguide.js

npm i tourguidejs

Why do I need Tourguide.js

Every time you build you next awesome web app, you sit back and stare lovingly at your handy-work :) But then inevitably someone comes along asking one and the same inconvenient question: "So, how do I use it?"

You try to explain, but people are just not getting it! You write how-tos, lengthy docs, and step-by-step guides, and yet, nothing seems to be enough.

This is why we built Tourguide.js - a simple yet powerful explainer utility, designed to help you make the reply a little bit less painful. Because, let's face it - picture is worth a 1000 words:

c833d152648344c9428ff8397c5b4ded.png

Getting started

There are a few ways you can use Tourguide.js

Fiddle with it

Want to see how it works right away? Try on JSFiddle

CommonJS

Download tourguide.min.js, add it to your project libraries, and then include it on page:

ES Module support

If you use ES modules in your project (Webpack, Rollup) import Tourguide.js like so:

import Tourguide from "tourguide/tourguide.esm.js";

Usage

Before use, Tourguide.js must be instantiated:

var tourguide = new Tourguide({options});

root: root element the tour steps will attach to; default is document.body

selector: if you want to use content based tour approach you can use this option to specify the common selector for the tour steps; default is [data-tour]

animationspeed: speed of all tour built-in animations; default is 300

padding: additional padding to add to step highlighter; default is 5(px)

steps: if you choose to take JSON based tour approach provide use this property to provide the data; default is null

src: if you want to load the tour from a remote URL you may specify it here; default is null

request: if you want to load the tour from a remote URL you may provide request headers here

onStart: callback function triggered when the tour starts

onStop: callback function triggered when tour stops

onComplete: callback triggered when tour completes

onStep: callback triggered when a tour step is shown

onAction: callback triggered when user clicks on the highlighted element

Once instantiated you can use tourguide instance a several different ways:

Content based approach

Simplest approach is to read the descriptions right off the elements on page. This works best if you are using an MVC approach in your application. Simply add tour descriptions to the HTML elements in your page template:

Collaborate

step: tour step sequence number

title: tour step title

content: tour step description

image?: tour step illustration

?* indicates the property is optional*

In this mode you can simply use Tourguide.js as-is:

var tourguide = new Tourguide();

tourguide.start();

JSON based approach

You may also write your own steps definition using JSON notation:

`[`

` {`

` "selector": null,`

` "step": 1,`

` "title": "Lets take a moment and look around Docsie library",`

` "content": "Click a button to advance to the next step of this tour.
To stop this tour at any time click a button in the top-right corner.",`

` "image": "https://somehost.com/image.jpeg"`

` },`

` {`

` "selector": "[data-component=library]:first-of-type",`

` "step": 2,`

` "title": "Shelf",`

` "content": "Just like a real library <mark>Docsie</mark> starts with <dfn>shelves</dfn>. Each <dfn>shelf</dfn> represnts a separate collection of ideas. You may think of them as individual websites, or website sections."`

` }`

`]`

selector?: CSS selector used to find the target element (optional)

step: tour step sequence number

title: tour step title

content: tour step description

image?: tour step illustration (optional)

?* indicates the property is optional*

Once you have the complete JSON description for each of your tour steps you will have to initialize Tourguide.js passing your JSON as steps: property:

var steps = [...];

var tourguide = new Tourguide({steps: steps});

tourguide.start();

Remote URL approach

You may also want to load the steps remotely. To do so simply provide the target src as one of the Tourguide.js init params:

var tourguide = new Tourguide({src: "https://somedomain.com/tours/guide.json"});

tourguide.start();

Controlling the tour

Once your tour has started you have several ways to manually control the tour flow:

tourguide.start([step])

Start the tour at any time by calling start(). You may optionally provide the step number to start the tour at a specific step (by default a tour always starts at step 1):

tourguide.start(2)

tourguide.stop()

Stop the tour at any moment by calling stop()

tourguide.next()

Causes tour to go to the next step in the sequence

tourguide.previous()

Causes tour to go to the previous step in the sequence

tourguide.go(step)

Causes tour to go to the step specified

tourguide.go(2)

Additional properties

tourguide.currentstep: returns the current step object

tourguide.length: return the number of steps on the tour

tourguide.steps: returns the tour steps as JSON notation

tourguide.hasnext: return true if there are steps remaining in the tour, otherwise returns false

tourguide.options: returns Tourguide.js options object

Attaching callbacks

Tourguide.js supports several helpful callbacks to help you better control the tour. You may optionally pass the callback functions into the tour instance at initialization time:

var tourguide = new Tourguide({

`onStart:function(options){...},`

`onStop:function(options){...},`

`onComplete:function(){...},`

`onStep:function(currentstep, type){...},`

`onAction:function(currentstep, e){...}`

});

onStart

Fires when the guided tour is started. The callback function will receive a single param:

options: tour options object

onStop

Fires when the guided tour stops. The callback function will receive a single param:

options: tour options object

onComplete

Fires when the guided tour is complete. The callback function will receives no params.

NOTE: onStop is always fired first, before onComplete is fired

onStep

Fires when tour step is activated. The callback function receives two params:

currentstep: tour step object

type: string representing the current direction of the tor; can be one of: "previous" | "next"

onAction

Fires when user has clicked on the step target. The callback function receives two params:

Step object

Each step of the tour is wrapped into a Step class. This allows you to have a direct access to the individual step properties and actions:

target: returns the target element step is attached to

el: returns the step view element

show(): show step element

hide(): hide step element

You can obtain the current step object an any time during the tour execution by calling tourguide.currentstep property:

var currentstep = tourguide.currentstep;

var stepTarget = currentstep.target;

var stepView = currentstep.el;

License

Tourguide.js is licensed under BSD 3-Clause "New" or "Revised" License

A permissive license similar to the BSD 2-Clause License, but with a 3rd clause that prohibits others from using the name of the project or its contributors to promote derived products without written consent.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在设计数据结构的校园导游程序时,我们通常会使用一种结构化的方来组织信息,如栈、队列、链表、树或图等数据结构。这里是一个简单的Python示例,使用了栈(Stack)来模拟一个校园导游,游客可以按照路线访问景点: ```python class Place: def __init__(self, name, location): self.name = name self.location = location class TourGuide: def __init__(self, campus_map): self.campus_map = campus_map self.current_place = None def start_tour(self, starting_point): if starting_point in self.campus_map: self.current_place = self.campus_map[starting_point] print(f"现在在 {self.current_place.name},景点位置: {self.current_place.location}") else: print("起点不在地图中,请重新选择。") def next_stop(self): if self.current_place is not None: if self.current_place.next_stop is not None: self.current_place = self.current_place.next_stop print(f"前往下一个景点: {self.current_place.name}, 地点: {self.current_place.location}") else: print("已到达行程结束,请返回起点或选择其他路线。") else: print("没有当前景点,请先开始游览。") # 示例校园地图,你可以根据实际需要扩展 campus_map = { "A楼": Place("A楼", "中心区"), "图书馆": Place("图书馆", "A楼旁边"), "食堂": Place("食堂", "B楼"), "B楼": Place("B楼", "食堂附近"), # 添加更多景点... } tour_guide = TourGuide(campus_map) tour_guide.start_tour("A楼") # 假设从A楼开始 tour_guide.next_stop() # 按照栈的顺序依次游览 ``` 这个例子只是一个基础版本,实际的校园导游程序可能需要更复杂的数据结构来存储景点信息,比如使用链表连接景点,或者使用图来表示景点之间的关联。此外,你还可以添加搜索功能,用户输入目的地直接导航,或者支持多线程/异步处理以支持并发访问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值