大前端 作者:云帮手 2024-10-07 14:04:41 阅读:130
granim.js 是一个开源 JavaScript 库,专门用于创建流畅和交互式的渐变动画。这些动画可以作为网页的背景,也可以给其他元素添加渐变动画,如按钮或滑块的视觉反馈。还可以为文字加上渐变效果,为用户带来视觉上的吸引力。
// js var granimInstance = new Granim({ element: '#canvas-basic', direction: 'diagonal', isPausedWhenNotInView: true, states : { "default-state": { gradients: [ ['#ff9966', '#ff5e62'], ['#00F260', '#0575E6'], ['#e1eec3', '#f05053'] ] } }});
// js var granimInstance = new Granim({ element: '#canvas-complex', direction: 'left-right', isPausedWhenNotInView: true, states : { "default-state": { gradients: [ [ { color: '#833ab4', pos: .2 }, { color: '#fd1d1d', pos: .8 }, { color: '#38ef7d', pos: 1 } ], [ { color: '#40e0d0', pos: 0 }, { color: '#ff8c00', pos: .2 }, { color: '#ff0080', pos: .75 } ], ] } } });
// js var granimInstance = new Granim({ element: '#canvas-image-blending', direction: 'top-bottom', isPausedWhenNotInView: true, image : { source: '../assets/img/bg-forest.jpg', blendingMode: 'multiply' }, states : { "default-state": { gradients: [ ['#29323c', '#485563'], ['#FF6B6B', '#556270'], ['#80d3fe', '#7ea0c4'], ['#f0ab51', '#eceba3'] ], transitionSpeed: 7000 } } }
API 介绍:
image: 包含图像选项的对象。
destroy(): 销毁实例并移除事件监听器。