A lightweight, dependency-free JavaScript library for perfectly replicating the Live Photo (dynamic photo) effect taken with mobile phones on web pages.
Usage Showcase
Live
Dynamic Image Showcase
Installation
Download the latest versions of livephoto.js and livephoto.css files from GitHub and place them in your web project.
After importing livephoto.js, call the initLivePhoto function to initialize the component. You can pass a configuration object to customize the component’s behavior.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
const config = { autoplay: true, // Whether to auto-play (when entering the viewport) hover_to_play: true, // Whether to enable hover-play click_to_play: true, // Whether to enable click-play lazy_load: true, // Whether to enable lazy loading threshold: 0.8, // The visible ratio that triggers auto-play badge: true, // Whether to display the Live badge badge_text: "Live", // Badge text badge_position: "bottom-left", // Badge position: bottom-left, bottom-right, top-left, top-right loading_animation: true, // Whether to display a loading animation preload: "auto", // Preload option: 'auto', 'metadata', 'none' keep_observing: false, // Whether to continue observing the element hover_delay: 300, // Hover delay time (milliseconds) weixin_disable_autoplay: true, // Whether to disable auto-play in WeChat's built-in browser }; initLivePhoto(config);
Notes
Video Format: It is recommended to use MP4 format encoded with H.264 to ensure compatibility with most browsers.
Performance: Although the plugin has been optimized, please note that video files should not be too large, and it is recommended to host video resources on a fast CDN.
Browser Support: Ensure your browser supports HTML5 video playback. After testing, Xiaomi Browser will convert the video to a video player, although it does not affect viewing, you will lose the opportunity to download the static image and the dynamic playback experience.
WeChat Browser: Due to the strict restrictions on auto-play in WeChat’s built-in browser, it is recommended to enable the weixin_disable_autoplay option to avoid white screen issues caused by auto-play.
Contributions
Welcome to submit Issues and Pull Requests!
License
MIT
Support
If this plugin has helped you, please give a star ⭐. If you encounter any problems while using it, please submit an Issue.