I recently worked hard on webkit masks that use CSS3 gradients to transition between images. I preferred to add the style tag to the head tag, which is dynamically created by my calculations. And also I used CSS3 animation. Something like that:
var cssStr = '<style id="myTransition">.myTransition_wipe{' + '-webkit-mask-size: 200% 200%;' + '-webkit-mask-repeat: no-repeat;' + '-webkit-animation: wipe 2s;' + '-webkit-animation-direction: normal;' + '-webkit-animation-iteration-count: 1;' + '-webkit-animation-fill-mode: forwards;' + '-webkit-mask-position: offsetLeftS 0;' + '-webkit-mask-image: -webkit-gradient(linear, left top, right top, ' + 'color-stop(0%, transparent), color-stop(20%, transparent), ' + 'color-stop(25%, transparent), color-stop(30%, transparent), ' + 'color-stop(50%, rgba(0, 0, 0, 1)), color-stop(98%, rgba(0, 0, 0, 1)), ' + 'color-stop(100%, rgba(0, 0, 0, 1)));}' + '@-webkit-keyframes wipe {' + '0% { -webkit-mask-position: offsetLeftS 0; }' + '100% { -webkit-mask-position: offsetLeftD 0; }' + '}' + '</style>'; var compStyle = getComputedStyle(currentElement); var width = parseInt(compStyle.getPropertyValue("width")); var height = parseInt(compStyle.getPropertyValue("height")); cssStr = cssStr.replace(/offsetLeftS/g, '-' + (width * 1) + 'px'); cssStr = cssStr.replace(/offsetLeftD/g, '+' + (width * 1) + 'px'); $('head').append(cssStr);
When I want to apply a transition, I remove the style tag with its identifier and myTransition_wipe class from it, and then add a new head tag and add it to the element too,
Please note:. You must save the styles that the element should have after the animation is completed, and add them immediately after the animation. Otherwise, when you remove the class name and style tag, everything will be reset.
Luck