這篇文章主要講解了“怎么使用Smartour”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來(lái)研究和學(xué)習(xí)“怎么使用Smartour”吧!
成都創(chuàng)新互聯(lián)成立于2013年,我們提供高端重慶網(wǎng)站建設(shè)公司、成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)站定制、成都營(yíng)銷網(wǎng)站建設(shè)、微信平臺(tái)小程序開(kāi)發(fā)、微信公眾號(hào)開(kāi)發(fā)、seo優(yōu)化排名服務(wù),提供專業(yè)營(yíng)銷思路、內(nèi)容策劃、視覺(jué)設(shè)計(jì)、程序開(kāi)發(fā)來(lái)完成項(xiàng)目落地,為石涼亭企業(yè)提供源源不斷的流量和訂單咨詢。
Smartour 被構(gòu)建成了 umd
和 es module
模塊,允許用戶通過(guò)不同的方式引入。
npm install smartour
/* ES Modules */ import Smartour from 'smartour/dist/index.esm.js' /* CommandJS */ const Smartour = require('smartour') /* <script> */ <script src="smartour/dist/index.js"></script>
Smartour 提供了一個(gè)非常簡(jiǎn)單的 API focus()
, 這是高亮一個(gè)元素最簡(jiǎn)單的方式。
let tour = new Smartour() tour.focus({ el: '#basic-usage' })
插槽 slot
是用于為高亮元素提供描述的 html 字符串。
let tour = new Smartour() tour.focus({ el: '#pure-string', slot: 'This is a pure string' })
let tour = new Smartour() tour.focus({ el: '#html-string', slot: ` <div> <p>This is a html string</p> </div> ` })
插槽的位置可以選擇4個(gè)不同的方向: top
, right
, left
, bottom
.
設(shè)置 options.slotPosition
屬性即可覆蓋默認(rèn)的 top
位置。
let tour = new Smartour() tour.focus({ el: '#slot-positions', slot: `top`, options: { slotPosition: 'top' // 默認(rèn)為 `top` } })
插槽所定義的元素也可以綁定事件。我們通過(guò) keyNodes
屬性來(lái)為插槽元素綁定事件。
keyNodes
是內(nèi)容為一系列 keyNode
的數(shù)組。 屬性 keyNode.el
是一個(gè) css 選擇器,而 keyNode.event
屬性則是對(duì)應(yīng)元素所綁定的事件。
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!!') } }] })
有的時(shí)候頁(yè)面需要不止一個(gè)導(dǎo)覽。Smartour 允許你把一系列的導(dǎo)覽通過(guò) .queue()
放在一起,然后挨個(gè)挨個(gè)地展示它們。
舉個(gè)例子:
let tour = new Smartour() tour .queue([{ el: '.li-1', options: { layerEvent: tour.next.bind(tour) }, slot: 'This is the 1st line.' }, { el: '.li-2', options: { layerEvent: tour.next.bind(tour) }, slot: 'This is the 2nd line.' }, { el: '.li-3', options: { layerEvent: tour.next.bind(tour) }, slot: 'This is the 3rd line.' }])
Smartour 是一個(gè)構(gòu)建函數(shù),它接收一個(gè) options
參數(shù)去覆蓋其默認(rèn)選項(xiàng)。
讓我們看看它的默認(rèn)選項(xiàng)是什么樣子的:
{ prefix: 'smartour', // class 前綴 padding: 5, // 高亮區(qū)域內(nèi)邊距 maskColor: 'rgba(0, 0, 0, .5)', // 帶透明值的遮罩層顏色 animate: true, // 是否使用動(dòng)畫 slotPosition: 'top' // 默認(rèn)的插槽位置 layerEvent: smartour.over // 遮罩層點(diǎn)擊事件,默認(rèn)為結(jié)束導(dǎo)覽 }
除了 .focus()
,.queue()
和 .run()
API 以外,Smartour 還提供了另外三個(gè) API 專門用于控制導(dǎo)覽的展示。
.next()
:展示下一個(gè)導(dǎo)覽(只能配合 .queue()
使用)。
.prev()
:展示上一個(gè)導(dǎo)覽(只能配合 .queue()
使用)。
.over()
:結(jié)束全部導(dǎo)覽。
Smartour 通過(guò) element.getBoundingClientRect()
api 來(lái)獲取目標(biāo)元素的寬高和位置信息,然后放置一個(gè)帶著 box-shadow
樣式的元素在其之上作為高亮區(qū)域。
由于點(diǎn)擊事件無(wú)法再 box-shadow
的區(qū)域里觸發(fā),所以 Smartour 還放置了一個(gè)全屏透明的遮罩層用于綁定 layerEvent
事件。
高亮區(qū)域和插槽都被設(shè)置為 absolute
。當(dāng)頁(yè)面滾動(dòng)時(shí),document.documentElement.scrollTop
或者 document.documentElement.scrollLeft
的值就會(huì)變化,然后 Smartour 會(huì)實(shí)時(shí)修正它的位置信息。
感謝各位的閱讀,以上就是“怎么使用Smartour”的內(nèi)容了,經(jīng)過(guò)本文的學(xué)習(xí)后,相信大家對(duì)怎么使用Smartour這一問(wèn)題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
分享文章:怎么使用Smartour
文章URL:http://chinadenli.net/article18/gidgdp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供關(guān)鍵詞優(yōu)化、定制開(kāi)發(fā)、標(biāo)簽優(yōu)化、網(wǎng)站設(shè)計(jì)公司、App設(shè)計(jì)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)