好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Smartour

Smartour 介绍

一旦网站改变了UI,通常他们会设置 一个 导游列表来告诉访问者,一些模块被移动到其他地方。 我们将其命名为“导游”,Smartour是 一个 使导游更容易的 解决方 案。?

在遇到网页 内容 有着较大调整的时候,往往需要 一个 导览 功能 去告诉 用户 ,某某 功能 已经调整到另外 一个 位置。比较常规的办法是 添加 一个 蒙层,高亮 显示 被调整的区域,然后通过 文字 介绍去完成引导。我们把这个 功能 称为“导览”,而 Smartour 则把这个导览的 功能 抽离出来,提供了 一个 开箱即用的 解决方 案。

Install

Smartour 被构建成了 umd 和 es module 模块,允许 用户 通过不同的方式引入。

npm install smartour

/* ES Modules */

import Smartour from 'smartour/ dis t/index.esm.js'

/* Commandjs */

const Smartour = require('smartour')

/* <script> */

<script src="smartour/ dis t/index.js"></script>

基本 用法

Smartour 提供了 一个 非常简单的 API focus(),这是高亮 一个 元素最简单的方式。

let tour = new Smartour()

tour.focus({

el: '#basic-usage'

})

插槽 Slot

插槽 slot 是用于为高亮元素提供描述的 html 字符串。

纯字符串:

let tour = new Smartour()

tour.focus({

el: '#pure-string',

slot: 'This is a pure string'

})

html 字符串

let tour = new Smartour()

tour.focus({

el: '#html-string',

slot: `

<div>

<p>This is a html string</p>

</div>

`

})

插槽位置

插槽的位置可以选择4个不同的方向: top,right,left,b ott om.

设置 options.slotPosition 属性 即可覆盖 默 认的 top 位置。

let tour = new Smartour()

tour.focus({

el: '#slot-positions',

slot: `top`,

options: {

slotPosition: 'top' // 默 认为 `top`

}

})

插槽事件

插槽所定义的元素也可以绑定事件。我们通过 keyNodes 属性 来为插槽元素绑定事件。

keyNodes 是 内容 为一系列 keyNode 的数组。 属性 keyNode.el 是 一个 css 选择器,而 keyNode.event 属性 则是对应元素所绑定的事件。

let tour = new Smartour()

tour.focus({

el: '.slot-events-demo',

options: {

slotPosition: 'right'

},

slot: `

Click here to occur an alert event

</button>

Click here to occur an alert event

</button>

`,

keyNodes: [{

el: '.occur-1',

event: () => { alert('Event!!') }

},{

el: '.occur-2',

event: () => { alert('Another event!!') }

}]

})

Queue

有的时候 页面 需要不止 一个 导览。Smartour 允许你把一系列的导览通过 .queue() 放在一起,然后挨个挨个地展示它们。

举个例子:

let tour = new Smartour()

tour

.queue([{

el: '.li-1',

options: {

layerEvent: tour.next.bind(tour)

},

slot: 'This is the 1st line.'

},{

el: '.li-2',

slot: 'This is the 2nd line.'

},{

el: '.li-3',

slot: 'This is the 3rd line.'

}])

.run() // 别忘了 调用 `run()` 方法 去展示第 一个 导览

选项

Smartour 是 一个 构建 函数 ,它接收 一个 options 参数去覆盖其 默 认选项

让我们看看它的 默 认选项是什么样子的:

{

prefix: 'smartour',// class 前缀

padding: 5,// 高亮区域内边距

maskColor: 'rgba(0,.5)',// 带透明值的遮罩层颜色

animate: true,// 是否使用动画

slotPosition: 'top' // 默 认的插槽位置

layerEvent: smartour.over // 遮罩层点击事件, 默 认为结束导览

}

APIs

除了 .focus(),.queue() 和 .run() API 以外,Smartour 还提供了另外三个 API 专门用于控制导览的展示。?

?.next():展示下 一个 导览(只能配合 .queue() 使用)。?

.prev():展示上 一个 导览(只能配合 .queue() 使用)。?

.over():结束全部导览。

Smartour 的原理

Smartour 通过 element.getBoundingClientRect() api 来 获取 目标元素的宽高和位置信息,然后放置 一个 带着 Box -shadow 样式的元素在其之上作为高亮区域。

由于点击事件无法再 Box -shadow 的区域里触发,所以 Smartour 还放置了 一个 全屏透明的遮罩层用于绑定 layerEvent 事件。

高亮区域和插槽都被设置为 absolute。当 页面 滚动时,document.documentElement.scrollTop 或者 document.documentElement.scrollLeft 的值就会变化,然后 Smartour 会实时修正它的位置信息。

?

网站地址 : https://jrainlau.github.io/smartour/

GitHub: https://github.com/jrainlau/smartour

网站描述: 让网页导览变得更简单

Smartour官方网站

官方网站: https://jrainlau.github.io/smartour/

如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。

查看更多关于Smartour的详细内容...

  阅读:27次

上一篇

下一篇

第1节:react-dates    第2节:Pica    第3节:Pikaday    第4节:scalable.js    第5节:date-fns    第6节:WOW.js    第7节:ngDialog    第8节:lazysizes.js    第9节:Flickity    第10节:react-swipeable-views    第11节:ueditor    第12节:screenfull.js    第13节:Darkmode.js    第14节:react-native-masonry    第15节:PhotoClip.js    第16节:vue-core-image-upload    第17节:PixelMatch    第18节:number-flip    第19节:hashids.js    第20节:vue-awesome-swiper    第21节:layzr.js    第22节:Kalendae    第23节:slideout.js    第24节:Layx    第25节:tinydate    第26节:soundmanager2.js    第27节:flv.js    第28节:vue2-animate    第29节:impress.js    第30节:angular-calendar    第31节:jsPDF    第32节:ReLaXed    第33节:xterm.js    第34节:Fawn    第35节:Glider.js    第36节:KindEditor    第37节:Pressure.js    第38节:Kiwi    第39节:FastDom    第40节:pnotify    第41节:vue-tour    第42节:Scene.js    第43节:galleria    第44节:smoothscroll.js    第45节:bubbly-bg.js    第46节:countUp.js    第47节:MediaElement.js    第48节:popper.js    第49节:Imager.js    第50节:quill.js    第51节:Split.js    第52节:vue-baidu-map    第53节:push.js    第54节:circles    第55节:SweetAlert2    第56节:ng2-toasty    第57节:gitmoji    第58节:sockette    第59节:Clusterize.js    第60节:Botpress    第61节:Awaity.js    第62节:zoom.js    第63节:Masonry    第64节:BetterScroll    第65节:atrament.js    第66节:vanilla-tilt.js    第67节:bignumber.js    第68节:uppy    第69节:dragula.js    第70节:placeholder.js    第71节:supercluster    第72节:angular-async-local-storage    第73节:PreloadJS    第74节:jwplayer    第75节:typeahead.js    第76节:tinyColor.js    第77节:tiptap    第78节:Bespoke.js    第79节:rrule.js    第80节:iScroll.js    第81节:maptalks.js    第82节:siema    第83节:Vidage.js    第84节:particles.js    第85节:SpreadJS    第86节:canvi.js    第87节:vue-virtual-scroller    第88节:Keypress.js    第89节:ng-file-upload    第90节:handsontable    第91节:remotestorage.js    第92节:vue-cute-timeline    第93节:pace.js    第94节:OwO    第95节:FrenchKiss.js    第96节:store.js    第97节:DPlayer    第98节:x2js    第99节:math-as-code    第100节:laverna    第101节:fine-uploader    第102节:Mermrender    第103节:proposal-bigint    第104节:packery    第105节:instantclick    第106节:simple-uploader.js    第107节:js-cookie    第108节:Draggable    第109节:CurrencyFormatter.js    第110节:reframe.js    第111节:hopscotch.js    第112节:mailgo.js    第113节:proj4js    第114节:AlloyFinger    第115节:delighters.js    第116节:UMeditor    第117节:lovefield    第118节:react-datasheet    第119节:BotUI    第120节:jsAnim    第121节:Video.js    第122节:highlight    第123节:polacode    第124节:Croppie.js    第125节:microlight    第126节:Odometer.js    第127节:Fuse.js    第128节:Moment Timezone    第129节:Drop.js    第130节:Headroom.js    第131节:tui.image-editor    第132节:Choices.js    第133节:lory    第134节:x-editable    第135节:vue-uploader    第136节:Algolia Places    第137节:TheaterJS    第138节:minigrid    第139节:ParticleEffectsButtons    第140节:anyupload    第141节:glide.js    第142节:Respond.js    第143节:vue-quill-editor    第144节:zeroclipboard    第145节:Keyboard    第146节:weapp.socket.io    第147节:qrcode.js    第148节:pjax    第149节:spy-debugger    第150节:nprogress    第151节:co.js    第152节:ajv    第153节:vue-grid-layout    第154节:reattempt    第155节:rapid.js    第156节:Proton    第157节:AgentMaps    第158节:Numeral.js    第159节:layDate    第160节:BigPicture.js    第161节:WebSlides    第162节:react-timeline-gantt    第163节:Stream.js    第164节:typed.js    第165节:accessible-html5-video-player    第166节:HTMLHint    第167节:AlloyCrop    第168节:collect.js    第169节:nanobar.js    第170节:logline    第171节:moment-timezone    第172节:Nimiq    第173节:list.js    第174节:cropper.js    第175节:vue-particles    第176节:Draggin.js    第177节:got    第178节:heatmap.js    第179节:react-color    第180节:forgJs    第181节:vue-good-table    第182节:TheoremJS    第183节:When.js    第184节:outils    第185节:SoundJS    第186节:Rythm.js    第187节:ripplet.js    第188节:cleave.js    第189节:ShuffleText    第190节:wangEditor    第191节:angularjs-slider    第192节:draft-js    第193节:vue-filepond    第194节:zooming.js    第195节:chroma.js    第196节:vue-tap    第197节:vue-snotify    第198节:sweetalert    第199节:mescroll.js    第200节:blurify.js    第201节:uos    第202节:Scraperjs    第203节:bricks.js    第204节:Please.js    第205节:a11y-dialog    第206节:Mercury Editor    第207节:GLightbox    第208节:superstruct    第209节:jeelizFaceFilter    第210节:Shepherd.js    第211节:monaco-editor    第212节:ImmortalDB    第213节:clipboard.js    第214节:Magenta.js    第215节:jsmpeg    第216节:notice.js    第217节:Ladda    第218节:slugify    第219节:Awesomplete    第220节:tinytime    第221节:translater.js    第222节:share.js    第223节:debug.js    第224节:eagle.js    第225节:Avgrund    第226节:src2png    第227节:vue-content-loader    第228节:tingle.js    第229节:DecorativeLetterAnimations    第230节:rangeslider.js    第231节:WebODM    第232节:cropbox.js    第233节:superplaceholder.js    第234节:shine.js    第235节:tastySelect    第236节:Fathom    第237节:FileAPI    第238节:Fitty    第239节:LABjs    第240节:vue-croppa    第241节:progress.js    第242节:prepack    第243节:wavesurfer.js    第244节:xo    第245节:Moment.js    第246节:lightgallery.js    第247节:Colorify.js    第248节:rellax    第249节:vue-js-popover    第250节:Liike.js    第251节:pieces.js    第252节:FastScan    第253节:ConditionerJS    第254节:qrious    第255节:Switch.js    第256节:widget    第257节:popbox.js    第258节:jsconsole    第259节:SVG-edit    第260节:Squire    第261节:JSZip    第262节:color-thief    第263节:Voca.js    第264节:Seen.js    第265节:layer    第266节:yall.js    第267节:imgResize    第268节:TremulaJS    第269节:vega    第270节:reveal.js    第271节:Keymaster.js    第272节:Barba.js    第273节:lozad.js    第274节:Pushbar.js    第275节:nodeppt    第276节:Luxon    第277节:Evaporate.js    第278节:humane.js    第279节:Watch.js    第280节:clamp.js    第281节:store    第282节:notie.js    第283节:regexgen    第284节:Driver.js    第285节:Feature.js    第286节:math.js    第287节:turbolinks    第288节:vue-tinder    第289节:Kibo    第290节:React LoadCon    第291节:cartodb    第292节:vue-i18n    第293节:jStorage    第294节:Ocrad.js    第295节:autosize    第296节:Animatic.js    第297节:vue-upload-component    第298节:fbt    第299节:Tone.js    第300节:dsa.js    第301节:cms.js    第302节:rainbow    第303节:trix    第304节:Day.js    第305节:zepto.fullpage    第306节:zingtouch    第307节:pdfkit    第308节:ZangoDB    第309节:join-monster    第310节:mailcheck.js    第311节:plyr    第312节:infinite-scroll    第313节:micron.js    第314节:emergence.js    第315节:miment    第316节:Vuescroll.js    第317节:lib-flexible    第318节:randomColor.js    第319节:nanoid    第320节:artipub    第321节:JavaScript-Load-Image    第322节:pdfmake.js    第323节:Awesome-qr.js    第324节:vee-validate    第325节:timeago.js    第326节:RegexHub    第327节:angular-file-upload    第328节:mock.js    第329节:Editor.js    第330节:validate.js    第331节:rcpress    第332节:hammer.js    第333节:NodePlayer.js    第334节:Amplitude.js    第335节:currency.js    第336节:iziToast    第337节:promise.js    第338节:PDF.js    第339节:bootlint.js    第340节:Notyf    第341节:canvas-nest.js    第342节:Canvas Gauges    第343节:ElasticProgress    第344节:qart.js    第345节:vue-lazyload    第346节:resumable.js    第347节:viz.js    第348节:marktext    第349节:onfire.js    第350节:in-view    第351节:You-Dont-Need-Momentjs    第352节:Slang    第353节:APlayer    第354节:localResizeIMG    第355节:history.js    第356节:intro.js    第357节:baffle.js    第358节:colorable    第359节:any-rule    第360节:basicScroll    第361节:iTyped.js    第362节:Summernote    第363节:BLazy.js    第364节:prism.js    第365节:Exif.js    第366节:PouchDB    第367节:Datomish    第368节:postcss-pxtorem    第369节:gmaps.js    第370节:alex    第371节:decimal.js    第372节:Simple-Ajax-Uploader    第373节:zxcvbn    第374节:webuploader    第375节:Jwerty    第376节:indigo-player    第377节:geo-maps    第378节:dancer.js    第379节:oraclejet    第380节:notification-logger    第381节:ScrollBooster    第382节:naivechain    第383节:baguetteBox.js    第384节:v-distpicker    第385节:Mousetrap    第386节:Simditor    第387节:Dropzone.js    第388节:box-js    第389节:ACE Editor    第390节:sentinel.js    第391节:tracking.js    第392节:Shave    第393节:smartcrop.js    第394节:wysihtml5    第395节:select2    第396节:Chance.js    第397节:bounce.js    第398节:ScrollingLettersAnimation    第399节:Filepond    第400节:stackedit    第401节:AR.js    第402节:libRmath.js    第403节:MProgress.js    第404节:howler.js    第405节:Ganja.js    第406节:labella.js    第407节:Parser    第408节:Waves    第409节:flatpickr    第410节:validator.js    第411节:saveSvgAsPng.js    第412节:responsive-nav.js    第413节:Vue.Draggable    第414节:Smartour    第415节:progressbar.js    第416节:vue-notification    第417节:Popcorn.js    第418节:Micromodal.js    第419节:ExpandingGridItemAnimation    第420节:Sortable.js    第421节:Echo.js    第422节:Cerebral    第423节:strman    第424节:PhotoSwipe    第425节:spop.js    第426节:CommentCoreLibrary    第427节:d8    第428节:Editor.md    第429节:proppy.js    第430节:UglifyJS    第431节:Tippy.js    第432节:Cashify    第433节:tui.editor    第434节:rome    第435节:Vue2Editor    第436节:Spacetime    第437节:Snap.js    第438节:tui.calendar    第439节:Timesheet.js    第440节:PDFObject