Updating animation-duration in Javascript

后端 未结 3 1676
梦毁少年i
梦毁少年i 2021-01-21 00:54

After changing the animation-duration (or in this case, -webkit-animation-duration) property via JavaScript with setProperty(\"-webkit-animation-

3条回答
  •  清歌不尽
    2021-01-21 01:23

    Setting the style element directly using the [] to access either the vendor-prefixed or native css prop. will allow you to re-apply the animation duration property and change the rotational speed of the planet. No jquery needed. It's also worth mentioning that at the time of writing Firefox supports a non-prefixed version of the css property, while there is either mixed support or vendor-prefix support for other browsers. If considering using these animations, a given developer should seriously consider their potential user-base and probably not make this a core feature of web app. See more support info here:

    http://caniuse.com/#feat=css-animation

    Le code:

    orbitFactor = 1e6
    
    function updateSpeed(event) {
        var orbitDiv = document.getElementById("Mercury-orbit");
        orbitDiv.style["-webkit-animation-duration"] = event.target.value + "s";
    }
    
    function updateDiameter(event) {
        var planetDiv = document.getElementById("Mercury");
        planetDiv.style["width"] = event.target.value + "px";
        planetDiv.style["height"] = event.target.value + "px";
    }
    
    document.getElementById("orbit-period").addEventListener("change", updateSpeed);
    document.getElementById("planet-diameter").addEventListener("change", updateDiameter);
    

提交回复
热议问题