Widgets (Opt-in)

Five independent, advanced widgets. Three require a separate CSS file (listed at the top of this page) - you never include the JS logic manually: molique-script.js detects the widget by its class on the page and fetches the right module from js/modules/ itself.

1. What to choose

Widget When Requires CSS file
.before-after-slider Transformations, projects, retouching - comparing two photos. molique-style-before-after.css
.btn-magnetic A CTA button meant to "attract" the cursor on desktop. None - pure JS.
.speed-dial A floating action button (FAB) with a handful of shortcuts. molique-style-speed-dial.css
.share-bar Sharing an article to social media. molique-style-share.css
.scroll-to-top Returning to the top of a long page. None - a core component.

2. Before / After Slider

A hidden <input type="range"> covering the whole widget drives the CSS variable --position - it's what moves the line and handle, and clips the "before" photo via clip-path. A native range gives keyboard support (arrow keys) with nothing extra to write.

After Before
<div class="before-after-slider">
  <img src="after.jpg" class="before-after-img img-after" alt="After">
  <img src="before.jpg" class="before-after-img img-before" alt="Before">
  <input type="range" class="slider-control" min="0" max="100" value="50">
  <div class="slider-line"></div>
  <div class="slider-handle"></div>
</div>
Class What it does
.before-after-slider The wrapper. Carrier for the --position variable (defaults to 50%).
.img-after The "after" photo - the bottom layer, in normal flow (sets the widget's height).
.img-before The "before" photo - the top layer, clipped via clip-path according to --position. The class order in the HTML doesn't matter - layering is decided by z-index, not DOM order.
.slider-control The invisible input[type=range] covering the whole area - the real controller.
.slider-line / .slider-handle Purely visual - they follow --position and don't intercept clicks (pointer-events: none).

3. Magnetic button

Add .btn-magnetic to any element - it follows the cursor within its hover radius. The class has no CSS of its own: the whole effect is an inline style="transform: translate(…)" set by JS on every mousemove.

<button class="btn-primary btn-magnetic">
  Magnetic button
</button>

Pointer devices only

The script checks matchMedia('(pointer: fine)') and doesn't attach the listener at all on touch (phone, tablet) - the button behaves normally, with no trace of the effect.

4. Speed Dial

A floating action button (FAB) with hidden shortcuts. It expands on :hover of the ENTIRE widget OR when any of its children gets focus (e.g. after clicking the main button) - so it works with mouse, touch, and keyboard. Zero JavaScript.

<!-- Defaults to position: fixed; bottom/right: 30px -->
<div class="speed-dial">
  <div class="speed-dial-actions">
    <button class="speed-dial-action" aria-label="Send an email"><svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-envelope-simple"></use></svg></button>
    <button class="speed-dial-action" aria-label="Call"><svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-phone"></use></svg></button>
  </div>
  <button class="speed-dial-main">+</button>
</div>
Class What it does
.speed-dial position: fixed in the bottom-right corner - always, with no class to move the corner (see pitfall #1).
.speed-dial-main The main round 56px button.
.speed-dial-actions The container for the shortcuts - hidden by default (opacity: 0; visibility: hidden).
.speed-dial-action A single round 44px shortcut.

5. Sharing widget

A bar of social-media buttons. The data-network value decides the behavior - facebook/twitter/linkedin/whatsapp open a share-link popup, native triggers the system share sheet (Web Share API).

<div class="share-bar">
  <button class="share-btn" data-network="facebook">f</button>
  <button class="share-btn" data-network="twitter">t</button>
  <button class="share-btn" data-network="native"><svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-export"></use></svg></button>
</div>
Class / attribute What it does
.share-bar The wrapper. Positioned as a floating vertical bar by default - overridden with an inline style to horizontal, in context, in the demo above.
.share-btn A single button. This - not .share-bar - is the selector that triggers the autoloader.
data-network facebook / twitter / linkedin / whatsapp / native. Any other value - the button does nothing.

6. Scroll to top

A single button, added once at the end of <body>. Visibility and scrolling are permanently handled by the core molique-script.js (like the sidebar toggle in the admin panel) - there's no separate module to register.

Forced .is-visible class here - normally applied after scrolling 400px.

<button class="scroll-to-top" aria-label="Back to top">
  <svg class="icon" aria-hidden="true"><use href="img/icons-sprite.svg#ph-arrow-up"></use></svg>
</button>
Class What it does
.scroll-to-top position: fixed, bottom-right corner. Invisible until it gets .is-visible.
.is-visible Set by the script after the page scrolls past 400px. Click: window.scrollTo({ top: 0, behavior: 'smooth' }).

7. Pitfalls

1 .speed-dial and .scroll-to-top on the same page

Both have identical default coordinates - position: fixed; bottom: 30px; right: 30px; - so used together they'll land exactly on top of each other (.scroll-to-top on top, higher z-index). If you need both, move one of them with your own style or CSS rule, e.g. bottom: 100px.

2 Photos with different aspect ratios in the Before/After slider

The widget's height is set by .img-after (height: auto, natural aspect ratio). .img-before has forced height: 100% - if its aspect ratio differs from the "after" photo's, it will be stretched or squeezed relative to the original.

3 No Web Share API support ends in a native alert()

The data-network="native" button on a browser without support (older desktop Chrome, Firefox) shows a blocking alert('Your browser doesn't support…') instead of silently hiding or switching to another option. If your target is mainly desktop, consider dropping this button in favor of specific networks.

8. Related pages