智能向导是一个jQuery向导插件,可以将长内容拆分为一个循序渐进的交互式向导界面。非常适合表单向导和基于步骤的导游。
1.在网页中加载Bootstrap的样式表(可选,自v5.0.0起)。
<link rel="stylesheet" href="bootstrap.min.css" />
2.加载核心样式表智能向导.css以及您在网页中选择的主题CSS。
<!-- Core Stylesheet --> <link href="./dist/css/smart_wizard.min.css" rel="stylesheet" /> <!-- Optional SmartWizard themes --> <link href="./dist/css/smart_wizard_arrows.min.css" rel="stylesheet"> <link href="./dist/css/smart_wizard_dots.min.css" rel="stylesheet"> <link href="./dist/css/smart_wizard_round.min.css" rel="stylesheet"> <link href="./dist/css/smart_wizard_square.min.css" rel="stylesheet"> <!-- All In One --> <link href="./dist/css/smart_wizard_all.min.css" rel="stylesheet" />
3.智能向导的基本HTML结构。
<div id="smartwizard">
<ul class="nav">
<li>
<a class="nav-link" href="#step-1">
Step 1
</a>
</li>
<li>
<a class="nav-link" href="#step-2">
Step 2
</a>
</li>
<li>
<a class="nav-link" href="#step-3">
Step 3
</a>
</li>
... more nav items here ...
</ul>
<div class="tab-content">
<div id="step-1" class="tab-pane" role="tabpanel">
Step 1
</div>
<div id="step-2" class="tab-pane" role="tabpanel">
Step 2
</div>
<div id="step-3" class="tab-pane" role="tabpanel">
Step 3
</div>
... more steps here ...
</div>
</div>
4.在网页末尾加载jQuery库和jQuery智能向导插件的脚本。
<script src="/path/to/cdn/jquery.min.js"></script> <script src="./dist/js/jquery.smartWizard.min.js"></script>
5.使用默认选项初始化智能向导。就是这样。
$('#smartwizard').smartWizard();
6.这个例子展示了如何通过AJAX从外部数据源加载步骤:
<ul class="nav">
<li class="nav-item">
<a class="nav-link" href="#step-1" data-repo="jquery-smarttab">
<strong>SmartTab</strong><br />repository details from GitHub
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#step-2" data-repo="smartwizard">
<strong>SmartWizard</strong><br />repository details from GitHub
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#step-3" data-repo="jquery-smartcart">
<strong>SmartCart</strong><br />repository details from GitHub
</a>
</li>
</ul>
$("#smartwizard").on("stepContent", function(e, anchorObject, stepIndex, stepDirection) {
var repo = anchorObject.data('repo');
var ajaxURL = "https://api.npms.io/v2/package/" + repo;
// Return a promise object
return new Promise((resolve, reject) => {
// Ajax call to fetch your content
$.ajax({
method : "GET",
url : ajaxURL,
beforeSend: function( xhr ) {
// Show the loader
$('#smartwizard').smartWizard("loader", "show");
}
}).done(function( res ) {
// console.log(res);
var html = '<h2>Ajax data about ' + repo + ' loaded from GitHub</h2>';
html += '<br>URL: <strong>' + ajaxURL + '</strong>';
html += '<br>Name: <strong>' + res.collected.metadata.name + '</strong>';
html += '<br>Description: ' + res.collected.metadata.description;
html += '<br>Homepage: <a href="' + res.collected.github.homepage + '" >'+ res.collected.github.homepage +'</a>';
html += '<br>Keywords: ' + res.collected.metadata.keywords.join(', ');
// html += '<br>Clone URL: ' + res.clone_url;
html += '<br>Stars: ' + res.collected.github.starsCount;
html += '<br>Forks: ' + res.collected.github.forksCount;
html += '<br>Watchers: ' + res.collected.github.subscribersCount;
html += '<br>Open Issues: ' + res.collected.github.issues.openCount + '/' + res.collected.github.issues.count;
html += '<br><br>Popularity: ' + parseInt(res.score.detail.popularity * 100);
html += '<br>Quality: ' + parseInt(res.score.detail.quality * 100);
html += '<br>Maintenance: ' + parseInt(res.score.detail.maintenance * 100);
// Resolve the Promise with the tab content
resolve(html);
// Hide the loader
$('#smartwizard').smartWizard("loader", "hide");
}).fail(function(err) {
// Reject the Promise with error message to show as tab content
reject( "An error loading the resource" );
// Hide the loader
$('#smartwizard').smartWizard("loader", "hide");
});
});
});
7.所有可用于轻松自定义向导的默认选项。
$('#smartwizard').smartWizard({
// Initial selected step, 0 = first step
selected: 0,
// 'arrows', 'square', 'round', 'dots'
theme: 'basic',
// Nav menu justification. true/false
justified: true,
// Automatically adjust content height
autoAdjustHeight:true,
// Show url hash based on step
enableURLhash: true,
// Enable the back button support
backButtonSupport: true,
// Animation options
transition: {
// Animation effect on navigation, none|fade|slideHorizontal|slideVertical|slideSwing|css(Animation CSS class also need to specify)
animation: 'none',
// Animation speed. Not used if animation is 'css'
speed: '400',
// Animation easing. Not supported without a jQuery easing plugin. Not used if animation is 'css'
easing: '',
// Only used if animation is 'css'. Animation CSS prefix
prefixCss: '',
// Only used if animation is 'css'. Step show Animation CSS on forward direction
fwdShowCss: '',
// Only used if animation is 'css'. Step hide Animation CSS on forward direction
fwdHideCss: '',
// Only used if animation is 'css'. Step show Animation CSS on backward direction
bckShowCss: '',
// Only used if animation is 'css'. Step hide Animation CSS on backward direction
bckHideCss: '',
},
// Step bar options
toolbar: {
// none|top|bottom|both
position: 'bottom',
// show/hide a Next button
showNextButton: true,
// show/hide a Previous button
showPreviousButton: true,
// Extra html to show on toolbar
extraHtml: ''
},
// Anchor options
anchor: {
// Enable/Disable anchor navigation
enableNavigation: true,
// Activates all anchors clickable always
enableNavigationAlways: false,
// Add done state on visited steps
enableDoneState: true,
// When a step selected by url hash, all previous steps are marked done
markPreviousStepsAsDone: true,
// While navigate back, done state will be cleared
unDoneOnBackNavigation: false,
// Enable/Disable the done state navigation
enableDoneStateNavigation: true
},
// Keyboard options
keyboard: {
// Enable/Disable keyboard navigation(left and right keys are used if enabled)
keyNavigation: true,
// Left key code
keyLeft: [37],
// Right key code
keyRight: [39]
},
// Language variables for button
lang: {
next: 'Next',
previous: 'Previous'
},
// CSS Class settings
style: {
mainCss: 'sw',
navCss: 'nav',
navLinkCss: 'nav-link',
contentCss: 'tab-content',
contentPanelCss: 'tab-pane',
themePrefixCss: 'sw-theme-',
anchorDefaultCss: 'default',
anchorDoneCss: 'done',
anchorActiveCss: 'active',
anchorDisabledCss: 'disabled',
anchorHiddenCss: 'hidden',
anchorErrorCss: 'error',
anchorWarningCss: 'warning',
justifiedCss: 'sw-justified',
btnCss: 'sw-btn',
btnNextCss: 'sw-btn-next',
btnPrevCss: 'sw-btn-prev',
loaderCss: 'sw-loading',
progressCss: 'progress',
progressBarCss: 'progress-bar',
toolbarCss: 'toolbar',
toolbarPrefixCss: 'toolbar-',
},
// Array of disabled Steps
disabledSteps: [],
// Highlight step with errors
errorSteps: [],
// Array Steps warning
warningSteps: [],
// Hidden steps
hiddenSteps: [],
// Callback function for content loading
getContent: null,
});
8.可用的事件处理程序。
// When the plugin is initialized
$("#smartwizard").on("initialized", function(e) {
// do something
});
// When the plugin is loaded
$("#smartwizard").on("loaded", function(e) {
// do something
});
// Triggered just before leaving from a step
$("#smartwizard").on("leaveStep", function(e, anchorObject, stepIndex, nextStepNumber, stepDirection) {
// do something
});
// When a step is shown
$("#smartwizard").on("showStep", function(e, anchorObject, stepIndex, stepDirection, stepPosition) {
// do something
});
9.创建自己的向导控件的可用API方法。
// goto a specific step
$('#smartwizard').smartWizard('goToStep', stepIndex, force);
// update options
$('#smartwizard').smartWizard('setOptions', stepIndex);
// goto the next step
$('#smartwizard').smartWizard('next');
// goto the prev step
$('#smartwizard').smartWizard('prev');
// reset the wizard
$('#smartwizard').smartWizard('reset');
// change the state of step(s)
$('#smartwizard').smartWizard("setState", [1,3], "disable");
$('#smartwizard').smartWizard("setState", [2], "hide");
// unset the state of step(s)
$('#smartwizard').smartWizard("unsetState", [1,3], "disable");
// get the current step index
var stepIndex = $('#smartwizard').smartWizard("getStepIndex");
// show/hide content loader
$('#smartwizard').smartWizard("loader", "show");
$('#smartwizard').smartWizard("loader", "hide");
// get options info
$('#smartwizard').smartWizard("getOptions");
// get step info
$('#smartwizard').smartWizard("getStepInfo");
// adjust the content height of the current step
$('#smartwizard').smartWizard("fixHeight");
版本6.0.6(2022-10-03)
版本6.0.5(2022-08-08)
版本6.0.4(2022-07-31)
版本6.0.3(2022-07-31)
版本6.0.1(2022-06-27)
v5.1.1 (2020-07-11)
v5.0.0版本(2020-05-24)
版本4.4.1(2020-02-16)
第4.3.1版(2018年3月12日)
版本4.2.2(2017-03-27)
v4.2.1(2017年3月27日)
第4.1.7版(2017年2月21日)
第4.1.5版(2017-02-01)
第4.1.2版(2017-01-09)
第4.1.1版(2016-12-08)
2016-11-16