0.0.19 • Published 5 years ago

@sil/pointer v0.0.19

Weekly downloads
1
License
ISC
Repository
-
Last release
5 years ago

Pointer

Create an alternate pointer in your interface, or a specific pointer for a button. This directive makes it easily possible by adding it to the element. The directive throws you back two custom-properties which you can use to animate anything.

Install

Install the package

npm install @sil/pointer 

Import the package

import Pointer from '~/@sil/pointer 

Define the component:

Vue.directive(Pointer);

Use the component with default values:

<any-element v-pointer />

About

When the directive is added, it will give you back a --x and a --y which are the values of your pointer relative to the viewport. You can use for instance for a pointer or animated background.

Options

By default the directive will return you with the current x and why on the page.

optiondefaultdescription
centerfalseCalculate the value based on the center of the element
boxelementCalculate values based on either the element, viewport or the whole page
typepixelSee below
minnullMinimum return value for x and y
min_xnullMinimum return value for x
min_ynullMinimum return value for y
maxnullMaximum return value for x and y
max_xnullMaximum return value for x
max_ynullMaximum return value for y
var_x--xProperty name for X to place value on.
var_y--yProperty name for Y to place value on.

Type options:

typeoutput
default: pixelReturns a value in pixels
percentageReturns a value in percentage
scaleReturns a value between 0 to 1

Percentage

You can also choose type percentage, in this case directive will return the position of the pointer relative to the element which has the directive. When pointing in the ultimate center of the element the --x and --y will be 50%.

<any-element v-pointer="{ type: 'percentage' }">

Min / Max values

Give a min and max value to make sure the value doesn't go over the top.

<any-element v-pointer="{ type: 'percentage', min: 0, max: 100 }">

In this case the pointer won't give any value bigger than 100% and smaller than 0%.

Custom variables

By default the directive returns you a --x and --y. You can alter these by setting: (Make sure you add the -- otherwise your custom property won't work. )

<any-element v-pointer="{ x_var: '--horizontal', y_var: '--vertical' }">

This will return:

<any-element style="--horizontal: 50%; --vertical: 50%">

Examples

Button Background

<button v-pointer>Hoi</button>
button {
	display: inline-block;
	padding: 1rem 2rem;

	background-color: blue;
	border: none;

	font-family: sans-serif;
	font-size: 1rem;
	color: white;
}
button::before {
	content: '';

	position: absolute;
	top: var(
		--y,
		50%
	); /* --y comes from the directive, the 50% is just a fallback */
	left: var(--x, 50%);

	display: block;
	width: 200%;
	height: 200%;

	background-image: radial-gradient(
		closest-side,
		rgba(0, 0, 0, 1),
		rgba(0, 0, 0, 0)
	);
}

Body Pointer

With this your pointer will be just a black dot.

<body v-pointer>
	<!-- Your html here -->
</body>
body {
	pointer: none;
}
body::before {
	content: '';

	position: absolute;
	top: var(
		--y,
		50%
	); /* --y comes from the directive, the 50% is just a fallback */
	left: var(--x, 50%);

	display: block;
	width: 1rem;
	height: 1rem;

	background-image: radial-gradient(
		closest-side,
		rgba(0, 0, 0, 1) 100%,
		rgba(0, 0, 0, 0)
	);
}
0.0.19

5 years ago

0.0.18

5 years ago

0.0.17

5 years ago

0.0.16

5 years ago

0.0.15

5 years ago

0.0.14

5 years ago

0.0.13

5 years ago

0.0.12

5 years ago

0.0.11

5 years ago

0.0.10

5 years ago

0.0.9

5 years ago

0.0.8

5 years ago

0.0.7

5 years ago

0.0.6

5 years ago

0.0.5

5 years ago

0.0.4

5 years ago

0.0.3

5 years ago

0.0.2

5 years ago