An warware: popper.js shigar

Popper.js babban ษ—akin karatu ne mai ban sha'awa mai buษ—ewa wanda ke ba da injunan sakawa mai ฦ™arfi don tukwici na kayan aiki, popovers, zazzage-zazzagewa, da sauran kewayon sauran abubuwan gidan yanar gizo. ฦ˜arfinsa ya ta'allaka ne kan yadda yake saurin sarrafa ฦ™ididdiga masu rikitarwa, tare da ba da zaษ“uษ“ษ“ukan da za a iya daidaita su sosai ga masu haษ“akawa. Ko kun kasance ฦ™wararren Javascript dev, ko kuma farawa, gabatar da Popper.js zuwa saitin kayan aikinku na iya zama mai canza wasa.

Sanya Popper.js

Ana iya shigar da Popper.js cikin sauri ta hanyoyi daban-daban, shahararrun su ne CDN da NPM.

// via CDN
<script src="https://unpkg.com/@popperjs/core@2"></script>

// via NPM
npm install @popperjs/core

Laburaren na zamani ne, ma'ana za ku iya shigo da abin da kuke buฦ™ata kawai, rage girman gungu na ฦ™arshe don aikinku.

Amfani da Popper.js a cikin Lambar ku

Yanzu da muka shigar da Popper.js, za mu iya fara fahimtar yuwuwar sa a cikin aikace-aikacen mu. Bari mu yi tafiya ta hanyar mataki-mataki don aiwatar da kayan aiki na asali ta amfani da Popper.js.

Da farko, la'akari da html:

<button id="button" aria-describedby="tooltip">Hover me</button>
<div id="tooltip" role="tooltip">I'm a Tooltip</div> 

A cikin fayil ษ—in Javascript ษ—in mu, za mu gabatar da misalin Popper:

import { createPopper } from '@popperjs/core';

const button = document.querySelector('#button');
const tooltip = document.querySelector('#tooltip');

createPopper(button, tooltip);

A sama, mun fara shigo da aikin ฦ™irฦ™irarPopper daga ษ—akin karatu na mu. Bayan haka, muna zaษ“ar maษ“allin mu da abubuwan kayan aiki daga DOM, kuma mu kira CreatePopper akan su. Wannan yana yin lissafin sakawa ta atomatik kuma yana amfani da salo zuwa tukwici na kayan aiki.

Duban Kusa a CreatePopper Aiki

Aikin 'createPopper' shine zuciyar Popper.js kuma ya haษ—a da hujjoji biyu na tilas: abin da ake magana da shi da kuma sinadarin popper.

- Abubuwan tunani shine kashi wanda za'a sanya tip ษ—in kayan aikin Popper ษ—in ku - a cikin misalin da ke sama, maษ“allin mu.

- The popper element shine Tooltip ko popover kanta - a cikin misalin da ke sama, shi ne kayan aikin mu.

Bayan wuce waษ—annan azaman muhawara cikin ฦ™irฦ™irarPopper(), yana kula da samar da mahimman salon kayan aikin ku, yana ba shi damar 'pop' a daidai matsayi dangane da maษ“allin.

Popper.js babban ษ—akin karatu ne mai nauyi amma mai ฦ™arfi wanda zai iya haษ“aka ฦ™warewar mai amfani sosai. Yana ษ—aukar zafi mai yawa daga sarrafa kayan aikin kayan aiki da popovers, wanda ke ba mu, masu haษ“akawa, mu mai da hankali kan wasu mahimman abubuwan aikace-aikacen. Don haka, idan kuna neman mafi kyawun sarrafa overlays na kowane iri a cikin aikace-aikacenku, tabbas ba Popper.js harbi!

Shafi posts:

Leave a Comment