Magic Cursor
A creative, aesthetic Magic Cursor effects for your creative website.
Recently, customizations have begun to appear at the mouse pointer level to add an aesthetic and creative effect to the site.
Of course, we have taken into consediration the addition of this feature as an in-house component to facilitate its use only through data-uc-cursor
.
Below you will find how it works and all the options and settings you can implement.
By default, the cursor initiated on our framework and good to go just enable it by removing the disable-cursor
class from body
tag.
Usage
Any of these options can be applied to the component attribute. Separate multiple options with a space and also these options are CSS classes or Selectors.
To apply this component, add the data-uc-cursor
attribute to an element you want the cursor to interact with!
Hover to see how it interact!
<element data-uc-cursor
> ... </element>
By default when you added data-uc-cursor
attribute the cursor start to interact with that element, but, we made some built-in options to customize it more and below you will find out how!
This component attribute can accept multiple css classes by bootstrap or our exclusive built-in classes as well to customize it as you want.
The main cursor will inherit any classes you add on data-uc-cursor
attribute.
Size
You can customize the cursor size by adding xs
, sm
, md
, lg
classes as an option.
Color
You can customize the cursor color by adding text-{color}
and it will inherit that color as it's background.
<element data-uc-cursor="text-primary
"> ... </element>
Text
You can add your custom text to the cursor by adding data-uc-cursor-text
attribute on the same element or any child element and write your custom text just inside the text attribute.
<!-- On the same element that has "data-uc-cursor" -->
<element data-uc-cursor="" data-uc-cursor-text="Your text"
> ... </element>
<!-- On the child level works too -->
<element data-uc-cursor="">
<element data-uc-cursor-text="Your text"
></element>
</element>
Icon
You can add your custom icon to the cursor by adding data-uc-cursor-icon
attribute on the same element or any child element and write your custom icon class just inside the attribute.
<!-- On the same element that has "data-uc-cursor" -->
<element data-uc-cursor="" data-uc-cursor-icon="unicon-move icon-4"
> ... </element>
<!-- On the child level works too -->
<element data-uc-cursor="">
<element data-uc-cursor-icon="unicon-search icon-3"
></element>
</element>
You can use our integrated icons library Unicons or any icon library that only works via CSS classes, as well as, you can resize icons using our icon size instructions.
Stick effect
Stick is a great effect for your links, buttons and any UI element, this will add a creative touch to your UI/UX design and here is how it works by adding data-uc-cursor-stick
attribute on the same element that have main attribute and accepts CSS selectors like .elem
class, #elem
ID and > *
child selectors.
Let's find out how it works.
You just need to hover on the image and the button below to see it sticked!
Get started
<!-- ID selector -->
<element data-uc-cursor="" data-uc-cursor-stick="#element-stick"
>
<childElement id="element-stick"> ... </childElement>
</element>
<!-- Class selector -->
<element data-uc-cursor="" data-uc-cursor-stick=".element-stick"
>
<childElement class="element-stick"> ... </childElement>
</element>
<!-- Child node/tag selector -->
<element data-uc-cursor="" data-uc-cursor-stick="childElement"
>
<childElement> ... </childElement>
</element>
The Stick effect accpets only one selector to make the cursor stick on it!
Magnetic effect
Magnetic, the same as Stick effect both are too way great effects to add a creative touch to your UI/UX design and here is how it works by adding data-uc-magnetic
attribute on the element that you want this effect works on.
<!-- On element to be magneted -->
<element data-uc-cursor="opaque">
<childElement data-uc-magnetic> ... </childElement>
</element>
<!-- Only one selector by class to be magneted -->
<element data-uc-cursor="opaque" data-uc-magnetic=".magnetic-element">
<childElement class="magnetic-element"> ... </childElement>
<childElement> ... </childElement>
</element>
<!-- Select all the child elements to be magneted -->
<element data-uc-cursor="opaque" data-uc-magnetic="*">
<childElement> ... </childElement>
<childElement> ... </childElement>
<childElement> ... </childElement>
</element>
The Magnetic effect accpets one or multi-child selectors to make the cursor magnet on it!
Playground
As these effects are great now we will combine them to achive a creative fusion and here is how it works.
Sticked Social Icons:
<ul data-uc-cursor="md" data-uc-cursor-stick="*">
<li data-uc-cursor="text-dark" data-uc-cursor-icon="unicon-logo-github icon-3">
<a href="#"><i class="icon-3 unicon-logo-github"></i></a>
</li>
<li data-uc-cursor="text-blue" data-uc-cursor-icon="unicon-logo-twitter icon-3">
<a href="#"><i class="icon-3 unicon-logo-twitter"></i></a>
</li>
<li data-uc-cursor="text-secondary" data-uc-cursor-icon="unicon-logo-instagram icon-3">
<a href="#"><i class="icon-3 unicon-logo-instagram"></i></a>
</li>
</ul>
Creative Link:
<a href="#link"
data-uc-cursor="md text-secondary-200 inverse-text fw-bold"
data-uc-cursor-text="TOP"
data-uc-cursor-stick="i"
data-uc-magnetic="i">
<span>Scroll to</span>
<i class="unicon-arrow-up"></i>
</a>
Magnetic Gallery:
<div class="row g-5 child-cols-3" data-uc-magnetic="**" data-uc-cursor-stick=".stick-element">
<div>
<div class="ratio ratio-1x1 rounded-2 overflow-hidden"
data-uc-cursor="sm text-white inverse-text shadow-sm"
data-uc-cursor-icon="unicon-add icon-3">
<img src=" ... " alt="Image alt" data-uc-img>
<div class="stick-element position-absolute top-50 start-50 translate-middle d-inline-flex justify-center items-center">
<a class="position-cover" href="#link"></a>
</div>
</div>
</div>
...
</div>
Slider + Stick controls:
<div class="swiper" data-swiper="items: 1; prev: .swiper-nav-prev; next: .swiper-nav-next;">
<div class="swiper-wrapper">
<div class="swiper-slide">Slide 1</div>
<div class="swiper-slide">Slide 2</div>
<div class="swiper-slide">Slide 3</div>
</div>
<!-- Add Pagination -->
<div class="swiper-pagination" data-uc-cursor="xs text-white inverse-text" data-uc-cursor-stick=">*"></div>
<!-- Add Arrows -->
<div class="swiper-nav swiper-nav-prev position-absolute top-0 start-0 bottom-0 z-1 w-1/2" data-uc-cursor="md text-primary" data-uc-cursor-icon="unicon-arrow-left icon-3"></div>
<div class="swiper-nav swiper-nav-next position-absolute top-0 end-0 bottom-0 z-1 w-1/2" data-uc-cursor="md text-primary" data-uc-cursor-icon="unicon-arrow-right icon-3"></div>
</div>
Options
Any of these options or classes can be applied to the component attribute. Separate multiple options or classes with a space.
[data-uc-cursor]
Class |
Value |
Description |
opaque , exclusion , difference |
Mode |
Exclusion or opaque or difference are modes to invert the cursor color.
For ex [data-uc-cursor="difference"] .
|
xs , sm , md , lg , xl |
Size |
Set a size to your cursor via this classes.
For ex [data-uc-cursor="lg"] .
|
text-{*} |
Color |
You can set a background color to your cursor via all Bootstrap text coloring classes.
For ex [data-uc-cursor="text-primary"] .
|
opacity-{*} |
Opacity |
You can control the transparency of your cursor via all our extended Bootstrap Opacity classes.
For ex [data-uc-cursor="opacity-25"] .
|
transparent |
Transparent background |
You can make the cursor background transparent by using this class.
For ex [data-uc-cursor="transparent"] .
|
inverse-text |
Color Invert |
By default, the text color is white and by using this class will invert it to black. This feature works only when you set a [data-uc-cursor-text] or [data-uc-cursor-icon] .
For ex [data-uc-cursor="inverse-text"] .
|
fw-bold , fw-light |
Font Weight |
You can control the font-weight of your cursor text via Bootstrap font-weight classes.
For ex [data-uc-cursor="fw-bold"] .
|
[data-uc-cursor-text]
Option |
Value |
Description |
Your_Text |
Text/HTML |
This data attribute accepts only Text or HTML content.
For ex [data-uc-cursor-text="Hello World!"] .
|
[data-uc-cursor-icon]
Option |
Value |
Description |
unicon-{*} |
Icon class |
You can set an icon from our Icon Library or set your custom icon class.
For ex [data-uc-cursor-icon="unicon-search"] .
|
icon-{*} |
Icon size |
You can customize the icon size using our icon sizing instructions that start from 1 to 6 .
For ex [data-uc-cursor-icon="unicon-search icon-4"] .
|
[data-uc-cursor-stick]
Option |
Value |
Description |
.class , #id , >* or tag |
CSS Selector |
This data attribute accepts only CSS selectors and can work only for one selected element.
For ex [data-uc-cursor-stick=".stick-element"] and add stick-element class to only one element that you want the cursor to stick on it.
|
[data-uc-magnetic]
Option |
Value |
Description |
.class , #id , >* or tag |
CSS Selector |
This data attribute accepts only CSS selectors and can work for one or multiple selected elements.
For ex [data-uc-magnetic] or [data-uc-magnetic=".element"] and add element class to any element(s) that you want the cursor to interact with magnet.
|
JavaScript
Learn more about JavaScript components.
Cursor Initialization
const yourCursor
= new UCCursor(options);
Cursor Options
Option |
Value |
Default |
Description |
container |
string |
body |
The cursor will fly only on the boundaries of selected container. Can accept multi selectors. |
speed |
number |
0.7 |
Cursor speed when following the mouse pointer. Value on seconds. |
visibleTimeout |
number |
300 |
The cursor will appear after the timout you set. Value on milliseconds. |
ease |
string |
"expo.out" |
Cursor easing. |
stickForce |
number |
0 |
Cursor stick effect force. Value on seconds. |
stickMagneticForce |
number |
0.3 |
Cursor stick and magnetic force. Value on seconds. |
Magnetic Initialization
$("[data-uc-magnetic]").each(function () {
const $elements = this.dataset.ucMagnetic ? $(this).find(this.dataset.ucMagnetic) : $(this);
$elements.each(function () {
new UCMagnetic(this, yourCursor
);
});
});
Magnetic Options
Option |
Value |
Default |
Description |
x |
number |
0.4 |
Magnetic ratio for x-axis. |
y |
number |
0.4 |
Magnetic ratio for y-axis. |
s |
number |
0.3 |
Magnetic speed when mouse enter the element. |
rs |
number |
0.5 |
Magnetic return speed when mouse leave the element. |