自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Smartour,讓網(wǎng)頁導(dǎo)覽變得更簡單

開發(fā) 前端
在遇到網(wǎng)頁內(nèi)容有著較大調(diào)整的時(shí)候,往往需要一個(gè)導(dǎo)覽功能去告訴用戶,某某功能已經(jīng)調(diào)整到另外一個(gè)位置。比較常規(guī)的辦法是添加一個(gè)蒙層,高亮顯示被調(diào)整的區(qū)域,然后通過文字介紹去完成引導(dǎo)。我們把這個(gè)功能稱為“導(dǎo)覽”,而 Smartour 則把這個(gè)導(dǎo)覽的功能抽離出來,提供了一個(gè)開箱即用的解決方案。

 

項(xiàng)目地址:https://github.com/jrainlau/s...
官方示例:https://jrainlau.github.io/sm...

Install

Smartour 被構(gòu)建成了 umd 和 es module 模塊,允許用戶通過不同的方式引入。 

  1. npm install smartour  
  1. /* ES Modules */ 
  2. import Smartour from 'smartour/dist/index.esm.js' 
  3. /* CommandJS */ 
  4. const Smartour = require('smartour'
  5. /* <script> */ 
  6. <script src="smartour/dist/index.js"></script> 

基本用法

Smartour 提供了一個(gè)非常簡單的 API focus(), 這是高亮一個(gè)元素最簡單的方式。

  1. let tour = new Smartour() 
  2.  
  3. tour.focus({ 
  4.   el: '#basic-usage' 
  5. }) 

插槽 Slot

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

純字符串:

  1. let tour = new Smartour() 
  2.  
  3. tour.focus({ 
  4.   el: '#pure-string'
  5.   slot: 'This is a pure string' 
  6. }) 

Html 字符串

  1. let tour = new Smartour() 
  2.  
  3. tour.focus({ 
  4.   el: '#html-string'
  5.   slot: ` 
  6.     <div> 
  7.       <p>This is a html string</p> 
  8.     </div> 
  9.   ` 
  10. }) 

插槽位置

插槽的位置可以選擇4個(gè)不同的方向: toprightleftbottom.

設(shè)置 options.slotPosition 屬性即可覆蓋默認(rèn)的 top 位置。

  1. let tour = new Smartour() 
  2.  
  3. tour.focus({ 
  4.   el: '#slot-positions'
  5.   slot: `top`, 
  6.   options: { 
  7.     slotPosition: 'top' // 默認(rèn)為 `top
  8.   } 
  9. }) 

插槽事件

插槽所定義的元素也可以綁定事件。我們通過 keyNodes 屬性來為插槽元素綁定事件。

keyNodes 是內(nèi)容為一系列 keyNode 的數(shù)組。 屬性 keyNode.el 是一個(gè) css 選擇器,而 keyNode.event 屬性則是對應(yīng)元素所綁定的事件。

  1. let tour = new Smartour() 
  2.  
  3. tour.focus({ 
  4.   el: '.slot-events-demo'
  5.   options: { 
  6.     slotPosition: 'right' 
  7.   }, 
  8.   slot: ` 
  9.  
  10.       Click here to occur an alert event 
  11.     </button> 
  12.  
  13.       Click here to occur an alert event 
  14.     </button> 
  15.   `, 
  16.   keyNodes: [{ 
  17.     el: '.occur-1'
  18.     event: () => { alert('Event!!') } 
  19.   }, { 
  20.     el: '.occur-2'
  21.     event: () => { alert('Another event!!') } 
  22.   }] 
  23. }) 

Queue

有的時(shí)候頁面需要不止一個(gè)導(dǎo)覽。Smartour 允許你把一系列的導(dǎo)覽通過 .queue() 放在一起,然后挨個(gè)挨個(gè)地展示它們。

舉個(gè)例子:

  1. let tour = new Smartour() 
  2.  
  3. tour 
  4.   .queue([{ 
  5.     el: '.li-1'
  6.     options: { 
  7.       layerEvent: tour.next.bind(tour) 
  8.     }, 
  9.     slot: 'This is the 1st line.' 
  10.   }, { 
  11.     el: '.li-2'
  12.     options: { 
  13.       layerEvent: tour.next.bind(tour) 
  14.     }, 
  15.     slot: 'This is the 2nd line.' 
  16.   }, { 
  17.     el: '.li-3'
  18.     options: { 
  19.       layerEvent: tour.next.bind(tour) 
  20.     }, 
  21.     slot: 'This is the 3rd line.' 
  22.   }]) 

選項(xiàng)

Smartour 是一個(gè)構(gòu)建函數(shù),它接收一個(gè) options 參數(shù)去覆蓋其默認(rèn)選項(xiàng)。

讓我們看看它的默認(rèn)選項(xiàng)是什么樣子的:

  1.   prefix: 'smartour', // class 前綴 
  2.   padding: 5, // 高亮區(qū)域內(nèi)邊距 
  3.   maskColor: 'rgba(0, 0, 0, .5)', // 帶透明值的遮罩層顏色 
  4.   animate: true, // 是否使用動畫 
  5.   slotPosition: 'top' // 默認(rèn)的插槽位置 
  6.   layerEvent: smartour.over // 遮罩層點(diǎn)擊事件,默認(rèn)為結(jié)束導(dǎo)覽 

APIs

除了 .focus(),.queue() 和 .run() API 以外,Smartour 還提供了另外三個(gè) API 專門用于控制導(dǎo)覽的展示。

  • .next():展示下一個(gè)導(dǎo)覽(只能配合 .queue() 使用)。
  • .prev():展示上一個(gè)導(dǎo)覽(只能配合 .queue() 使用)。
  • .over():結(jié)束全部導(dǎo)覽。

Smartour 的原理

Smartour 通過 element.getBoundingClientRect() api 來獲取目標(biāo)元素的寬高和位置信息,然后放置一個(gè)帶著 box-shadow 樣式的元素在其之上作為高亮區(qū)域。

由于點(diǎn)擊事件無法再 box-shadow 的區(qū)域里觸發(fā),所以 Smartour 還放置了一個(gè)全屏透明的遮罩層用于綁定 layerEvent 事件。

高亮區(qū)域和插槽都被設(shè)置為 absolute。當(dāng)頁面滾動時(shí),document.documentElement.scrollTop 或者 document.documentElement.scrollLeft 的值就會變化,然后 Smartour 會實(shí)時(shí)修正它的位置信息。 

責(zé)任編輯:龐桂玉 來源: segmentfault
相關(guān)推薦

2009-06-18 15:51:52

SSL VPN負(fù)載均衡Array

2020-06-16 13:22:22

AI創(chuàng)新深度學(xué)習(xí)

2019-01-18 13:13:40

Facebook 開發(fā)開源

2013-07-31 14:19:06

Windows 8.1

2009-07-06 14:23:00

SSL VPNArray netwo

2009-06-19 10:16:10

巔峰訪談

2019-06-26 15:41:26

AI云原生云遷移

2021-03-15 10:29:50

人工智能

2009-08-19 19:16:21

CS1000統(tǒng)一通信北電

2016-09-08 23:58:42

云運(yùn)維 云數(shù)據(jù)中心

2024-11-18 08:33:56

2019-12-19 18:40:16

5G智慧城市智能教育

2011-11-09 11:13:55

Firefox 8

2023-12-01 16:00:48

Python結(jié)構(gòu)化模式

2014-08-01 09:50:39

Oracle營銷云Oracle Eloq

2011-09-15 10:35:12

Android應(yīng)用IOS應(yīng)用著裝搭配

2020-07-24 15:40:51

CSS前端代碼

2020-08-13 10:11:14

物聯(lián)網(wǎng)安全智能家居物聯(lián)網(wǎng)

2023-03-24 16:14:01

物聯(lián)網(wǎng)醫(yī)療保健

2015-05-05 11:18:18

大數(shù)據(jù)Hadoop技術(shù)處理
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號