ctrl-freaks / freezeframe.js

freezeframe.js is a library that pauses animated .gifs and enables them to animate on mouse hover / mouse click / touch event, or with trigger / release functions.
http://ctrl-freaks.github.io/freezeframe.js/
MIT License
1.41k stars 111 forks source link

Re-initialize script when props change #69

Closed alpezed closed 1 year ago

alpezed commented 4 years ago

Hi, I am using the react component and i just want to know if how can i reinitialize the script when the src props or image is change without reloading the page, for now if you can see the screenshot the old image is still exists and it's creating a nested div from freezeframe script.

2020-06-23 210438

nickforddev commented 4 years ago

Hmm this sounds like a real bug. I am in the process of porting the project to TypeScript, and will definitely address this asap.

nickforddev commented 4 years ago

@alpezed Can you show me how you are using the ReactFreezeframe component?

alpezed commented 4 years ago

Hi @nickforddesign

Here's the code my simple react component using ReactFreezeframe


/**
 * External dependencies
 */
import React, { Component } from 'react';
import ReactFreezeframe from 'react-freezeframe';

class GifPlayer extends Component {
    static slug = 'et_pb_better_gif_player';

    render() {
        const { image, on_hover, show_play } = this.props;

        const show_overlay = 'off' === on_hover && 'on' === show_play;

        if (!image) {
            return null;
        }

        return (
            <ReactFreezeframe 
                src={image}
                options={{
                    trigger: 'on' === on_hover ? 'hover' : 'click',
                    overlay: show_overlay ? true : false,
                }}
            />
        );
    }
}

export default GifPlayer;
nickforddev commented 4 years ago

Sorry for the lack of activity on this. I just published the TypeScript re-write of vue-freezeframe, and fixed this issue in that library. react-freezeframe is next on the list to get a TypeScript re-write, and I will fix this issue.