A lightweight image distortion effect that simulates viscous molten flow in the browser.
- Include files:
<link rel="stylesheet" href="style.css">
<img class="lava-effect" src="your-image.jpg" alt="">
<script src="src/molten-distortion.js"></script>- Optional: set values directly on the image with data attributes:
<img
class="lava-effect"
src="your-image.jpg"
data-molten-swirl-strength="6"
data-molten-swirl-speed="0.45"
data-molten-push-strength="3.5"
data-molten-warp-px="26"
data-molten-viscosity="0.00045"
data-molten-emitter-count="3"
>The plugin auto-attaches to all .lava-effect images.
The global object is window.MoltenDistortion.
MoltenDistortion.defaults: default settings objectMoltenDistortion.fromDataset(img): parsedata-molten-*options from an imageMoltenDistortion.attach(target, options?): attach/re-attach to one imageMoltenDistortion.attachAll(selector?, options?): attach to many imagesMoltenDistortion.destroy(target): destroy one instance
target can be an HTMLImageElement or a CSS selector string.
data-molten-sim-pixelsdata-molten-warp-pxdata-molten-viscositydata-molten-iterationsdata-molten-dampingdata-molten-gravitydata-molten-emitter-countdata-molten-emitter-radius-factordata-molten-swirl-strengthdata-molten-swirl-speeddata-molten-push-strengthdata-molten-time-scale
- Use local images or same-origin images to avoid canvas CORS restrictions.
- Lower
swirlSpeedfor slower circle rotation. - Raise
swirlStrengthfor stronger twisting.