File size: 18,680 Bytes
5f830d1 2b7567f 8122c36 a98e9c8 25ec032 5f830d1 e09eecc ed7c546 a98e9c8 ed7c546 2e0d6f9 25ec032 1337c0d 7fac605 66f1613 3a2c734 2b7567f 1923a66 25ec032 1923a66 2b7567f 25ec032 1923a66 e09eecc 1923a66 2b7567f 25ec032 2b7567f 1923a66 25ec032 2b7567f 25ec032 2b7567f e09eecc 25ec032 341b84c 25ec032 341b84c 25ec032 1de5288 25ec032 1de5288 8c52c69 fc53067 341b84c 1de5288 8c52c69 fc53067 8c52c69 1de5288 341b84c 1de5288 341b84c 6b18698 341b84c d52f2d6 341b84c d52f2d6 140aae9 d52f2d6 341b84c cfadc6c 341b84c e09eecc 341b84c e09eecc 341b84c cfadc6c 341b84c d315169 ddf993e 2e0d6f9 7ee7519 920a3e5 341b84c 492d0ff 341b84c 2e0d6f9 00c1eb6 341b84c e09eecc 341b84c cfadc6c 341b84c cfadc6c 341b84c c5e62d3 341b84c 7ee7519 341b84c 6f9d983 341b84c e09eecc 66f1613 e09eecc 2b7567f 6f9d983 e09eecc 66f1613 e09eecc 6f9d983 e09eecc 06b7251 e09eecc 6f9d983 5f830d1 d86254c 6f9d983 25ec032 1923a66 d52f2d6 140aae9 d52f2d6 5f830d1 06b7251 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 |
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Driver</title>
<meta name="description" itemprop="description" content="A light-weight, no-dependency, vanilla JavaScript library to drive the user's focus across the page"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/monokai.min.css">
</head>
<body>
<div class="page-wrap">
<section class="section__header" id="driver-demo-head">
<h1 class="brand">
<img id="logo_img" src="./images/driver.png"/>
<span id="name_driver">Driver.js</span>
</h1>
<p class="text-muted tagline">Light-weight, no-dependency, vanilla JavaScript engine to drive user's focus across
the
page</p>
<a id="animated-tour" href="javascript:void(0)" class="btn btn__example btn__dark">With Animation</a>
<a id="boring-tour" href="javascript:void(0)" class="btn btn__example btn__dark">Without Animation</a>
<div class="github-button top-30">
<!-- Place this tag where you want the button to render. -->
<a class="github-button" href="https://github.com/kamranahmedse/driver.js" data-size="large"
data-show-count="true" aria-label="Star kamranahmedse/driver.js on GitHub">Star</a>
</div>
</section>
<blockquote>
<p>A lightweight (~4kb gzipped) yet powerful JavaScript engine that helps you drive the user's focus on page.</p>
<p class="zero-bottom">Some sample use-cases can be creating powerful feature introductions, call-to-action
components, focus shifters etc.</p>
</blockquote>
<section class="section__purpose">
<h3>What are the features?</h3>
<p>Driver is compatible with all the major browsers and can be used for any of your overlay needs. Feature
introductions, focus shifters, call-to-action are just a few examples.</p>
<ul>
<li id="highlight_feature">π <strong>Highlight</strong> any (literally any) item on page</li>
<li id="interactions_feature">β <strong>Block user interactions</strong></li>
<li id="feature_introductions_feature">π£ Create <strong>feature introductions</strong></li>
<li id="focus_shifters_feature">π Add <strong>focus shifters</strong> for users</li>
<li id="customizable_feature">π οΈ Highly customizable β <strong>Use it anywhere</strong> for overlay</li>
<li id="keyboard_feature">β¨οΈ User Friendly β <strong>Controllable by keys</strong></li>
<li id="free_use_feature">π <strong>MIT Licensed</strong> β Free for personal and commercial use</li>
<li id="lightweight_feature">ποΈ Lightweight β Only <strong>~4kb</strong> when gzipped</li>
<li id="major_browsers_feature">π <strong>Consistent behavior</strong> across all major browsers</li>
</ul>
</section>
<hr class="hr__fancy">
<section class="section__how">
<h3>How does it do that?</h3>
<p>In it simplest, it puts the canvas on top of the whole page and then cuts the part that is over the element to be
highlighted and provides you several hooks when highlighting, highlighted or un-highlighting elements making it
highly customizable.</p>
</section>
<hr class="hr__fancy">
<section class="section__examples">
<div id="examples_section">
<h3>Can you show some Examples?</h3>
<p>Below you find some of the examples and sample use-cases on how you can use it. Run by clicking the
<code>RUN</code> button.</p>
</div>
<div id="single-element-no-popover" class="section__example">
<h4>Highlighting a Single Element β Without Popover</h4>
<p class="zero-bottom">If all you want is just highlight a single element, you can do that simply by passing the
selector</p>
<a href="#" class="btn__run-demo" id="run-single-element-no-popover">Show Demo</a>
<pre><code class="javascript">const driver = new Driver();
driver.highlight('#create-post');
</code></pre>
</div>
<hr class="hr__fancy">
<div class="section__example">
<p>A <strong>real world use-case</strong> for this could be highlighting an element when user is interacting with
it</p>
<pre><code class="javascript">const focusDriver = new Driver();
// Highlight the section on focus
document.getElementById('creation-input')
.addEventListener('focus', (e) => {
focusDriver.focus('#creation-input');
});
</code></pre>
<p class="top-20">Focus any of the inputs and see how it moves the highlight from one element to the other</p>
<div id="creation-forms">
<input type="text" id="creation-input" class="form-control" placeholder="Focus any of the inputs">
<input type="text" id="creation-input-2" class="form-control" placeholder="Focus any of the inputs">
<input type="text" id="creation-input-3" class="form-control" placeholder="Focus any of the inputs">
<input type="text" id="creation-input-4" class="form-control" placeholder="Focus any of the inputs">
</div>
</div>
<p>You can also turn off the animation or set the padding around the corner. More on it later.</p>
<hr class="hr__fancy">
<div id="single-element-with-popover" class="section__example">
<h4>Highlighting a Single Element β With Popover</h4>
<p>If you would like to show some details alongside the highlighted element, you can do that easily by specifying
title and description</p>
<a href="#" class="btn__run-demo" id="run-single-element-with-popover">Show Demo</a>
<pre><code class="javascript">const driver = new Driver();
driver.highlight({
element: '#some-element',
popover: {
title: 'Title for the Popover',
description: 'Description for it',
}
});
</code></pre>
<p class="top-20">You can modify the behavior of this popover also by a certain set of options. More on it
below.</p>
</div>
<hr class="hr__fancy">
<div id="single-element-with-popover-position" class="section__example">
<h4>Popover Positioning</h4>
<p>You can also, change the position of the popover to be either <code>left</code>, <code>left-center</code>, <code>left-bottom</code>, <code>top</code>, <code>top-center</code>, <code>top-right</code>,
<code>right</code>, <code>right-center</code>, <code>right-bottom</code> or <code>bottom</code>, <code>bottom-center</code>, <code>bottom-right</code>, <code>mid-center</code>.</p>
<a href="#" class="btn__run-demo" id="run-single-element-with-popover-position">Show Demo</a>
<pre><code class="javascript">const driver = new Driver();
driver.highlight({
element: '#some-element',
popover: {
title: 'Title for the Popover',
description: 'Description for it',
// position can be left, left-center, left-bottom, top,
// top-center, top-right, right, right-center, right-bottom,
// bottom, bottom-center, bottom-right, mid-center
position: 'left',
}
});
</code></pre>
</div>
<div class="section__example">
<div class="top-20 position-btns">
<a href="#" id="position-btn-left">On my Left</a>
<a href="#" id="position-btn-top">On my Top</a>
<a href="#" id="position-btn-bottom">On my Bottom</a>
<a href="#" id="position-btn-right">On my Right</a>
</div>
<p class="top-20">If you don't specify the position or specify it to be <code>auto</code>, it will automatically
find the suitable position for the popover and show it</p>
</div>
<hr class="hr__fancy">
<div id="single-element-with-popover-html" class="section__example">
<h4>HTML in Popovers</h4>
<p>You can also specify HTML in the body or the title of the popovers. Here is an example:</p>
<a href="#" class="btn__run-demo" id="run-single-element-with-popover-html">Show Demo</a>
<pre><code class="javascript">const driver = new Driver();
driver.highlight({
element: '#some-element',
popover: {
title: '<em>An italicized title</em>',
description: 'Description may also contain <strong>HTML</strong>'
}
});
</code></pre>
</div>
<p class="top-20">And of course it can be any valid HTML.</p>
<hr class="hr__fancy">
<div id="single-element-no-close" class="section__example">
<h4>Disable Close on Outside Click</h4>
<p>By default, driver.js gets reset if user clicks outside the highlighted element, you can disable this:</p>
<a href="#" class="btn__run-demo" id="run-single-element-no-close">Show Demo</a>
<pre><code class="javascript">const driver = new Driver({
allowClose: false,
});
driver.highlight({
element: '#some-element',
popover: {
title: '<em>An italicized title</em>',
description: 'Description may also contain <strong>HTML</strong>'
}
});
</code></pre>
<p class="top-20">
If you use this option, for multi-step driver, it would close after you are done with the popover or you can close it programmatically. For single element popover, you need to close it properly, otherwise it won't be closed
</p>
<pre><code class="javascript">driver.reset()</code>
</div>
<hr class="hr__fancy">
<div id="third-element-introduction" class="section__example">
<h4 id="first-element-introduction">Creating Feature Introductions</h4>
<p id="second-para-feature-introductions">You can also make powerful feature introductions to guide the users
about the features. Just provide an array of steps where each step specifies an element to highlight.</p>
<p id="third-para-feature-introductions">Below is just a quick example showing you how to combine the steps in
introduction.</p>
<a href="#" class="btn__run-demo" id="run-multi-element-popovers">Show Demo</a>
</div>
<pre><code class="javascript">const driver = new Driver();
// Define the steps for introduction
driver.defineSteps([
{
element: '#first-element-introduction',
popover: {
className: 'first-step-popover-class',
title: 'Title on Popover',
description: 'Body of the popover',
position: 'left'
}
},
{
element: '#second-element-introduction',
popover: {
title: 'Title on Popover',
description: 'Body of the popover',
position: 'top'
}
},
{
element: '#third-element-introduction',
popover: {
title: 'Title on Popover',
description: 'Body of the popover',
position: 'right'
}
},
]);
// Start the introduction
driver.start();
</code></pre>
<p class="top-20">This is just a quick example for the feature introduction. For a richer one, please have a look at
the
<a href="#" class="btn__example">"Quick Tour"</a></p>
<p>You may also turn off the footer buttons in popover, in which case user can control the popover using the arrows
keys on keyboard. Or you may control it using the methods provided by Driver.</p>
<hr class="hr__fancy">
<div id="element-without-popover" class="section__example">
<h4>Without Overlay</h4>
<p>You can create feature introductions and do everything listed above without overlays also. All you have to do
is just set the opacity to `0`.</p>
<a href="#" class="btn__run-demo" id="run-element-without-popover">Show Demo</a>
<pre><code class="javascript">const driver = new Driver({
opacity: 0,
});
driver.highlight({
element: '#run-element-without-popover',
popover: {
title: 'Title for the Popover',
description: 'Description for it',
position: 'top', // can be `top`, `left`, `right`, `bottom`
}
});
</code></pre>
<p class="top-20">..and you can do the same for the feature introductions</p>
</div>
<hr class="hr__fancy">
<div class="section__example">
<div id="api_section">
<h3>..and much much more</h3>
<p>Driver comes with many options that you can manipulate to make driver behave as you may like</p>
</div>
<h4>Driver Definition</h4>
<p>Here are the options that Driver understands</p>
<pre><code class="javascript">const driver = new Driver({
className: 'scoped-class', // className to wrap driver.js popover
animate: true, // Animate while changing highlighted element
opacity: 0.75, // Background opacity (0 means only popovers and without overlay)
padding: 10, // Distance of element from around the edges
allowClose: true, // Whether clicking on overlay should close or not
overlayClickNext: false, // Should it move to next step on overlay click
doneBtnText: 'Done', // Text on the final button
closeBtnText: 'Close', // Text on the close button for this step
nextBtnText: 'Next', // Next button text for this step
prevBtnText: 'Previous', // Previous button text for this step
showButtons: false, // Do not show control buttons in footer
keyboardControl: true, // Allow controlling through keyboard (escape to close, arrow keys to move)
scrollIntoViewOptions: {}, // We use `scrollIntoView()` when possible, pass here the options for it if you want any
onHighlightStarted: (Element) {}, // Called when element is about to be highlighted
onHighlighted: (Element) {}, // Called when element is fully highlighted
onDeselected: (Element) {}, // Called when element has been deselected
onReset: (Element) {}, // Called when overlay is about to be cleared
onNext: (Element) => {}, // Called when moving to next step on any step
onPrevious: (Element) => {}, // Called when moving to next step on any step
});
</code></pre>
</div>
<p class="top-20">Note that all the button options that you provide in the driver definition can be overridden for a
specific step by giving them in the step definition</p>
<div class="section__example">
<h4>Step Definition</h4>
<p>Here are the set of options that you can pass in each step i.e. an item in array of steps or the object that
you pass to <code>highlight</code> method</p>
<pre><code class="javascript">const stepDefinition = {
element: '#some-item', // Query selector string or Node to be highlighted
popover: { // There will be no popover if empty or not given
className: 'popover-class', // className to wrap this specific step popover in addition to the general className in Driver options
title: 'Title', // Title on the popover
description: 'Description', // Body of the popover
showButtons: false, // Do not show control buttons in footer
closeBtnText: 'Close', // Text on the close button for this step
nextBtnText: 'Next', // Next button text for this step
prevBtnText: 'Previous', // Previous button text for this step
}
};
</code></pre>
</div>
<div class="section__example">
<h4>API Methods</h4>
<p>Below are the set of methods that are available to you</p>
<pre><code class="javascript">const driver = new Driver(driverOptions);
const isActivated = driver.isActivated; // Checks if the driver is active or not
driver.moveNext(); // Moves to next step in the steps list
driver.movePrevious(); // Moves to previous step in the steps list
driver.start(stepNumber = 0); // Starts driving through the defined steps
driver.highlight(string|stepDefinition); // highlights the element using query selector or the step definition
driver.reset(); // Resets the overlay and clears the screen
driver.hasHighlightedElement(); // Checks if there is any highlighted element
driver.hasNextStep(); // Checks if there is next step to move to
driver.hasPreviousStep(); // Checks if there is previous step to move to
// Prevents the current move. Useful in `onNext` or `onPrevious` if you want to
// perform some asynchronous task and manually move to next step
driver.preventMove();
// Gets the currently highlighted element on screen
const activeElement = driver.getHighlightedElement();
const lastActiveElement = driver.getLastHighlightedElement();
activeElement.getCalculatedPosition(); // Gets screen co-ordinates of the active element
activeElement.hidePopover(); // Hide the popover
activeElement.showPopover(); // Show the popover
activeElement.getNode(); // Gets the DOM Element behind this element
</code></pre>
</div>
<p class="top-20">You can use a variety of options to achieve whatever you may want. I have some plans on improving
it further, make sure to keep an eye on the <a href="https://github.com/kamranahmedse/driver.js" target="_blank">GitHub
page</a></p>
</section>
<hr class="hr__fancy">
<div class="section__example">
<h4>Contributing</h4>
<p>You can find the contribution instructions on the <a href="https://github.com/kamranahmedse/driver.js"
target="_blank">GitHub page</a>. Feel free to submit an
issue, create a pull request or spread the word</p>
</div>
<hr class="hr__fancy">
<div class="section__example">
<p>A product by <a href="http://twitter.com/kamranahmedse" target="_blank">Kamran</a> produced out of boredom and
frustration after he gave up on trying to find a perfect solution to integrate journey introduction
and overlays.</p>
<a href="https://twitter.com/kamranahmedse?ref_src=twsrc%5Etfw"
class="twitter-follow-button mr-3"
data-show-screen-name="false"
data-size="large"
target="_blank"
data-show-count="true">Follow @kamranahmedse</a>
<a class="github-button" href="https://github.com/kamranahmedse"
data-size="large"
target="_blank"
data-show-count="true"
aria-label="Follow @kamranahmedse on GitHub">Follow</a>
</div>
</div>
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
<script async defer src="//buttons.github.io/buttons.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments);
}, i[r].l = 1 * new Date();
a = s.createElement(o),
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
m.parentNode.insertBefore(a, m);
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
ga('create', 'UA-58155965-1', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
|