i want make particle event in React component(current not animation) - css

i want make particle event in div element on React component using useRef
but it is not working animation.
codes
const particles = useRef<HTMLDivElement>(null!);
**set parent ref(paricles) and create child particle.
and set useCallback for set location child particle and animation**
const particleEffect = useCallback(() => {
console.log("???");
const np = particles.current.clientWidth / 70;
particles.current.innerHTML = "";
const childRe = [] as HTMLDivElement[];
for (let i = 0; i < np; i++) {
const child = document.createElement("div");
childRe.push(child);
}
for (let i = 0; i < np; i++) {
const w = particles.current.clientWidth;
const h = particles.current.clientHeight;
const rndw = Math.floor(Math.random() * w) + 1;
const rndh = Math.floor(Math.random() * h) + 1;
const widthpt = Math.floor(Math.random() * 12) + 3;
const opty = Math.floor(Math.random() * 5) + 2;
const anima = Math.floor(Math.random() * 12) + 8;
childRe[i].classList.add(`${classes(styles.particle)}`);
childRe[i].style.marginLeft = `${rndw}px`;
childRe[i].style.marginTop = `${rndh}px`;
childRe[i].style.width = `${widthpt}px`;
childRe[i].style.height = `${widthpt}px`;
childRe[i].style.background = "white";
childRe[i].style.opacity = `${opty}`;
childRe[i].style.animation = `move ${anima}s ease-in infinite `;
particles.current.appendChild(childRe[i]);
}
}, [particles.current]);
and then, i make eventHandler for call useCallback function
useEffect(() => {
if (!particles.current) {
return;
}
particleEffect();
window.addEventListener("resize", particleEffect);
window.addEventListener("load", particleEffect);
return () => {
window.removeEventListener("resize", particleEffect);
window.removeEventListener("load", particleEffect);
};
}, []);
in css
.particles {
position: absolute;
overflow: hidden;
width: 100%;
height: 100vh;
top: 0;
left: 0;
filter: blur(8px);
.particle{
border-radius: 50%;
position: absolute;
}
}
#keyframes move {
0%{
transform: translateX(0vh);
opacity: 0;
}
10%{
opacity: 1;
}
90%{
opacity: 1;
}
100%{
transform: translateX(45vh);
opacity: 0;
}
}
but animation css not working...
why is not working...?
what should i fix it?
example
https://codepen.io/ricardoolivaalonso/pen/agdRRB

Related

How to remove Group of CSS2DObject from the scene

I have a dynamic msg_arr array of strings that I want to visualize, and I want to remove the old errs Group of CSS2DObject from the scene before creating the new errors Group.
The problem in my case is that the new CSS2DObjects are added perfectly to the Group, but the reset: this.scene.remove(this.errs); is not working well!
Should I remove and create a new CSS2DRenderer??
Can you please tell me how can I be sure of resetting the whole old Group before creating the new one? thanks in advance.
var camera, scene, renderer, errs;
/**
ErrVisu class
*/
class ErrVisu{
constructor(scene){
this.scene = scene;
}
visuError=(x, y, errs)=>{
const x_mm = y * 0.8 - 8.8;
const y_mm = 2.5;
const z_mm = x * 0.8 - 2.4;
const circle = document.createElement('div');
circle.id = "circle";
circle.innerHTML = "!";
const objectCSS = new THREE.CSS2DObject(circle);
objectCSS.position.set(x_mm, y_mm, z_mm);
objectCSS.name = 'exc_' + x + y;
errs.add(objectCSS);
}
errsIface = (msg_arr) => {
this.scene.remove(this.errs);
this.errs = new THREE.Group();
this.errs.name = "errors";
for (let k in msg_arr) {
let p_xx_yy = msg_arr[k].split("_");
let x = Number(p_xx_yy[1]);
let y = Number(p_xx_yy[2]);
this.visuError(x, y, this.errs);
}
this.scene.add(this.errs);
}
}
/**
Create the scene, camera, renderer
*/
function init() {
scene = new THREE.Scene();
scene.background = new THREE.Color(0x21252d);
renderer = new THREE.WebGLRenderer({antialias: true});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
camera = new THREE.PerspectiveCamera(50, window.innerWidth / window.innerHeight, 1, 1000);
camera.position.x = 1;
camera.position.y = 4;
camera.position.z = 5;
scene.add(camera);
labelRenderer = new THREE.CSS2DRenderer();
labelRenderer.setSize( window.innerWidth, window.innerHeight );
labelRenderer.domElement.style.position = 'absolute';
labelRenderer.domElement.style.top = '0px';
document.body.appendChild( labelRenderer.domElement );
controls = new THREE.OrbitControls(camera, labelRenderer.domElement);
errs = new ErrVisu(scene);
let msg_arr_ = [ "p_06_08" ];
errs.errsIface(msg_arr_);
window.addEventListener('resize', onWindowResize);
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
labelRenderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame(animate);
render();
}
function render() {
renderer.render(scene, camera);
labelRenderer.render( scene, camera );
}
init();
animate();
#circle {
color: #ffffff;
background: #ff5500;
width: 30px;
height: 30px;
border-radius: 50%;
text-align: center;
font-size: 25px;
font-weight: bold;
display: inline-block;
animation: blinkingBackground 0.5s infinite;
}
#keyframes blinkingBackground {
0% {
opacity: 1;
}
25% {
opacity: 0.5;
}
50% {
opacity: 0.1;
}
75% {
opacity: 0.5;
}
100% {
opacity: 1;
}
}
<script src="https://cdn.jsdelivr.net/npm/three#0.122.0/build/three.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three#0.122.0/examples/js/controls/OrbitControls.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/three#0.122.0/examples/js/renderers/CSS2DRenderer.js"></script>
The solution ( source ) was to create an array of CSS2DObjects and to remove the items of that array from the scene rather than combining the Objects in a Group!:
errs.forEach((item) => {
this.scene.remove(item);
});
errs = [];
visuError=(x, y, errs, scene)=>{
const x_mm = y * 0.8 - 8.8;
const y_mm = 2.5;
const z_mm = x * 0.8 - 2.4;
const circle = document.createElement('div');
circle.id = "circle";
circle.innerHTML = "!";
const objectCSS = new CSS2DObject(circle);
objectCSS.position.set(x_mm, y_mm, z_mm);
objectCSS.name = 'exc_' + x + y;
scene.add(objectCSS);
errs.push(objectCSS);
}

Transition between colspan changes in Tailwind

I have some javascript which will change the col-span-{x} class of a div to correctly give the element its width on the page. I would like this change to be animated over a second instead of an instant jump.
<div class="card col-span-{colSpan} transition duration-1000">...</div>
As per the Tailwind docs, col-span-{number} classes are setting the grid-column CSS property (MDN), namely class names col-span-1 and col-span-2 correspond to grid-column: span 1 / span 1; and grid-column: span 2 / span 2;.
These grid-column shorthand property and its values are not animatable. So, you have to fight the headwind of animating the widths yourself, in a tedious way like this:
clone the animated grid cell element and its next neighbour
add transition: width 1s; to the style of clones
put the clones exactly over their originals using element.getBoundingClientRect() for their pixel position and dimensions
change the col-span-{number} class names in the origin elements as needed
get the pixel position and dimensions of the originals with new col-span-{number} classes
feed new widths to the clone elements
on the transitionend event, remove the clones and show the originals
Deal with the literal edge-cases when you change the col-span-{number} on an edgemost item.
Well, here's a demo that needs refactoring and resembles the good old Masonry layout.
let grid;
const hide = (elem) => {
elem.style.opacity = 0;
}
const show = (elem) => {
elem.style.opacity = 1;
}
const animateWidth = (elem) => {
const gridRect = grid.getBoundingClientRect();
const targetRect = elem.getBoundingClientRect();
const clone = elem.cloneNode();
clone.style.pointerEvents = 'none';
clone.innerHTML = elem.innerHTML + ' clone';
clone.classList.add('clone');
clone.style.position = 'absolute';
clone.style.zIndex = 999;
clone.style.transition = 'width 1s, left 1s, top 1s';
const oldWidth = targetRect.width;
clone.style.width = oldWidth + 'px';
const top = targetRect.y - gridRect.y;
clone.style.top = top ? top + 'px' : 0;
const left = targetRect.x - gridRect.x;
clone.style.left = left ? left + 'px' : 0;
grid.appendChild(clone);
hide(elem);
let nextSibling;
let nextSiblingClone;
if (elem.nextSibling && !elem.nextSibling.classList.contains('clone')) {
nextSibling = elem.nextSibling;
nextSiblingClone = createAndGetNextSiblingClone(elem.nextSibling);
}
elem.classList.toggle('col-span-1');
elem.classList.toggle('col-span-2');
const newWidth = elem.getBoundingClientRect().width;
clone.style.width = newWidth ? newWidth + 'px' : 0;
const newLeft = elem.getBoundingClientRect().x - gridRect.x;
clone.style.left = newLeft ? newLeft + 'px' : 0;
const newTop = elem.getBoundingClientRect().y - gridRect.y;
clone.style.top = newTop ? newTop + 'px' : 0;
if (nextSibling) {
const nextSiblingRect = nextSibling.getBoundingClientRect();
const nextSiblingLeft = nextSiblingRect.x - gridRect.x;
nextSiblingClone.style.left = nextSiblingLeft ? nextSiblingLeft + 'px' : 0;
const nextSiblingTop = nextSiblingRect.y - gridRect.y;
nextSiblingClone.style.top = nextSiblingTop ? nextSiblingTop + 'px' : 0;
}
clone.ontransitionend = (event) => {
show(elem);
if (event && event.target && event.target.parentNode) {
event.target.parentNode.removeChild(event.target);
}
}
}
const createAndGetNextSiblingClone = (elem) => {
const gridRect = grid.getBoundingClientRect();
const targetRect = elem.getBoundingClientRect();
const clone = elem.cloneNode();
clone.innerHTML = elem.innerHTML + ' clone';
clone.classList.add('clone');
clone.style.position = 'absolute';
clone.style.zIndex = 999;
clone.style.transition = 'left 1s, top 1s';
clone.style.pointerEvents = 'none';
clone.style.width = targetRect.width ? targetRect.width + 'px' : 0;
const top = targetRect.y - gridRect.y;
clone.style.top = top ? top + 'px' : 0;
const left = targetRect.x - gridRect.x;
clone.style.left = left ? left + 'px' : 0;
grid.appendChild(clone);
hide(elem);
clone.ontransitionend = (event) => {
show(elem);
if (event && event.target && event.target.parentNode) {
event.target.parentNode.removeChild(event.target);
}
}
return clone;
}
const onGridItemClick = (event) => {
animateWidth(event.target);
}
const displayTheGrid = () => {
grid = document.getElementById('grid');
'lightgreen lightblue #dabaf9 beige #ffbbbb #f9daba #99cefa'
.split(' ')
.forEach((color, index) => {
const gridItem = document.createElement('div');
gridItem.innerHTML = index;
gridItem.style.backgroundColor = color;
grid.appendChild(gridItem);
gridItem.onclick = onGridItemClick;
});
}
window.addEventListener('DOMContentLoaded', displayTheGrid);
* {
box-sizing: border-box;
}
#grid {
display: grid;
grid-template-columns: 20fr 20fr 20fr 20fr 20fr;
grid-gap: 10px;
margin-top: 10px;
position: relative;
}
#grid > div {
border-radius: 6px;
padding: 10px;
background-color: silver;
}
.col-span-1 {
grid-column: span 1 / span 1;
}
.col-span-2 {
grid-column: span 2 / span 2;
}
<!-- https://stackoverflow.com/questions/74571960 -->
<div id="grid"></div>
I don't know if with only transition property applied you can perform an animation on col-span.
Try to use transition-all instead of transition

Animated style-components perfomance issues

I found html/css snowfall animation. Html part of this animation is 200 divs with .snow class and here is the SCSS:
body {
background: radial-gradient(ellipse at bottom, #1b2735 0%, #090a0f 100%);
overflow-x: hidden;
filter: drop-shadow(0 0 10px white);
}
#function random_range($min, $max) {
$rand: random();
$random_range: $min + floor($rand * (($max - $min) + 1));
#return $random_range;
}
.snow {
$total: 200;
position: absolute;
width: 10px;
height: 10px;
background: white;
border-radius: 50%;
#for $i from 1 through $total {
$random-x: random() * 100vw;
$random-offset: random_range(-10, 10) * 1vw;
$random-x-end: $random-x + $random-offset;
$random-x-end-yoyo: $random-x + ($random-offset / 2);
$random-yoyo-time: random_range(3,8) / 10;
$random-yoyo-y: $random-yoyo-time * 100vh;
$random-scale: random();
$fall-duration: random_range(10, 30) * 1s;
$fall-delay: random(30) * -1s;
&:nth-child(#{$i}) {
opacity: random();
transform: translate($random-x, -10px) scale($random-scale);
animation: fall-#{$i} $fall-duration $fall-delay linear infinite;
}
#keyframes fall-#{$i} {
#{percentage($random-yoyo-time)} {
transform: translate($random-x-end, $random-yoyo-y) scale($random-scale);
}
to {
transform: translate($random-x-end-yoyo, 100vh) scale($random-scale);
}
}
}
}
I wanted to make a react component out of this animation, and I did it with styled-components:
const randomRange = (min: number, max: number) => {
return min + Math.random() * (max - min)
}
const DropAnimation = (docHeight: number, size:number) => {
const xstart = Math.random() * 100;
const xshift = randomRange(-10, 10);
const xmiddle = xstart + xshift;
const xend = xstart + xshift / 2;
const middlePercentage = randomRange(30, 80)
const animation = keyframes`{
0%{
transform: translate(${xstart}vw,-10px);
}
${middlePercentage}%{
transform: translate(${xmiddle}vw,${middlePercentage / 100 * docHeight}px);
}
100%{
transform: translate(${xend}vw,${docHeight - size}px);
}
}`
return animation
}
const StyledSnowflake = styled.div<StyledSnowflake>`
position: absolute;
width: ${p => p.size}px;
height: ${p => p.size}px;
border-radius: 50%;
background-color: ${p => p.color || 'white'};
animation: ${p => DropAnimation(p.docHeight, p.index,p.size)} ${p => randomRange(p.duration / 3, p.duration)}s
${p => -p.duration * Math.random()}s linear infinite;
filter: drop-shadow(0 0 10px ${p => p.color || 'white'});
opacity: ${p => p.opacity};
`
const SnowFlake: FC<Snowflake> = ({docHeight, duration, index, size}) => {
const opacity = Math.random();
const randomSize = Math.random() * size;
return <StyledSnowflake duration={duration} size={randomSize} opacity={opacity} docHeight={docHeight}
index={index}/>
}
Snowfall components renders 200 SnowFlake components. All I did is just copied css, but perfomance-wise my Snowfall component is much much worse, everything lagging quite hard. Why? What is the difference between rendering 200 divs from html and 200 styledComponent divs from react?
How can I make this work faster?
P.S. if this question is too stupid, please just leave me a few links where I could read about this. Honestly, I don't even know how to google this problem, because when I search for any kind of info I only see articles about efficient rendering in react, but I don't think this is what I actually need since I render my components once, but animation still performs poorly.
EDIT
I found out that creacting regular divs in react works fine like this:
<div>
{Array(200).fill(null).map((_item,i)=> <div key={i} className={styles.snow}></div>)}
</div>
But when I use styled-components and add animation for each of those everything starts lagging.

lightgallery doesnt work good

My gallery starts from my first img,but at counter its number 2, and when go back to first picture it shows me nothing, just black window (at first it shows me "src undefined", but now just black window). I want my first
picture to be number 1 in counter etc. i am not sure where is the problem, so i gave you js code from lightgallery here
(function() {
'use strict';
var defaults = {
mode: 'lg-slide',
// Ex : 'ease'
cssEasing: 'ease',
//'for jquery animation'
easing: 'linear',
speed: 600,
height: '100%',
width: '100%',
addClass: '',
startClass: 'lg-start-zoom',
backdropDuration: 150,
hideBarsDelay: 6000,
useLeft: false,
closable: true,
loop: true,
escKey: true,
keyPress: true,
controls: true,
slideEndAnimatoin: true,
hideControlOnEnd: false,
mousewheel: true,
getCaptionFromTitleOrAlt: true,
// .lg-item || '.lg-sub-html'
appendSubHtmlTo: '.lg-sub-html',
subHtmlSelectorRelative: false,
/**
* #desc number of preload slides
* will exicute only after the current slide is fully loaded.
*
* #ex you clicked on 4th image and if preload = 1 then 3rd slide and 5th
* slide will be loaded in the background after the 4th slide is fully loaded..
* if preload is 2 then 2nd 3rd 5th 6th slides will be preloaded.. ... ...
*
*/
preload: 0,
showAfterLoad: true,
selector: '',
selectWithin: '',
nextHtml: '',
prevHtml: '',
// 0, 1
index: false,
iframeMaxWidth: '100%',
download: true,
counter: true,
appendCounterTo: '.lg-toolbar',
swipeThreshold: 50,
enableSwipe: true,
enableDrag: true,
dynamic: false,
dynamicEl: [],
galleryId: 1
};
function Plugin(element, options) {
// Current lightGallery element
this.el = element;
// Current jquery element
this.$el = $(element);
// lightGallery settings
this.s = $.extend({}, defaults, options);
// When using dynamic mode, ensure dynamicEl is an array
if (this.s.dynamic && this.s.dynamicEl !== 'undefined' && this.s.dynamicEl.constructor === Array && !this.s.dynamicEl.length) {
throw ('When using dynamic mode, you must also define dynamicEl as an Array.');
}
// lightGallery modules
this.modules = {};
// false when lightgallery complete first slide;
this.lGalleryOn = false;
this.lgBusy = false;
// Timeout function for hiding controls;
this.hideBartimeout = false;
// To determine browser supports for touch events;
this.isTouch = ('ontouchstart' in document.documentElement);
// Disable hideControlOnEnd if sildeEndAnimation is true
if (this.s.slideEndAnimatoin) {
this.s.hideControlOnEnd = false;
}
// Gallery items
if (this.s.dynamic) {
this.$items = this.s.dynamicEl;
} else {
if (this.s.selector === 'this') {
this.$items = this.$el;
} else if (this.s.selector !== '') {
if (this.s.selectWithin) {
this.$items = $(this.s.selectWithin).find(this.s.selector);
} else {
this.$items = this.$el.find($(this.s.selector));
}
} else {
this.$items = this.$el.children();
}
}
// .lg-item
this.$slide = '';
// .lg-outer
this.$outer = '';
this.init();
return this;
}
Plugin.prototype.init = function() {
var _this = this;
// s.preload should not be more than $item.length
if (_this.s.preload > _this.$items.length) {
_this.s.preload = _this.$items.length;
}
// if dynamic option is enabled execute immediately
var _hash = window.location.hash;
if (_hash.indexOf('lg=' + this.s.galleryId) > 0) {
_this.index = parseInt(_hash.split('&slide=')[1], 10);
$('body').addClass('lg-from-hash');
if (!$('body').hasClass('lg-on')) {
setTimeout(function() {
_this.build(_this.index);
});
$('body').addClass('lg-on');
}
}
if (_this.s.dynamic) {
_this.$el.trigger('onBeforeOpen.lg');
_this.index = _this.s.index || 0;
// prevent accidental double execution
if (!$('body').hasClass('lg-on')) {
setTimeout(function() {
_this.build(_this.index);
$('body').addClass('lg-on');
});
}
} else {
// Using different namespace for click because click event should not unbind if selector is same object('this')
_this.$items.on('click.lgcustom', function(event) {
// For IE8
try {
event.preventDefault();
event.preventDefault();
} catch (er) {
event.returnValue = false;
}
_this.$el.trigger('onBeforeOpen.lg');
_this.index = _this.s.index || _this.$items.index(this);
// prevent accidental double execution
if (!$('body').hasClass('lg-on')) {
_this.build(_this.index);
$('body').addClass('lg-on');
}
});
}
};
Plugin.prototype.build = function(index) {
var _this = this;
_this.structure();
// module constructor
$.each($.fn.lightGallery.modules, function(key) {
_this.modules[key] = new $.fn.lightGallery.modules[key](_this.el);
});
// initiate slide function
_this.slide(index, false, false, false);
if (_this.s.keyPress) {
_this.keyPress();
}
if (_this.$items.length > 1) {
_this.arrow();
setTimeout(function() {
_this.enableDrag();
_this.enableSwipe();
}, 50);
if (_this.s.mousewheel) {
_this.mousewheel();
}
} else {
_this.$slide.on('click.lg', function() {
_this.$el.trigger('onSlideClick.lg');
});
}
_this.counter();
_this.closeGallery();
_this.$el.trigger('onAfterOpen.lg');
// Hide controllers if mouse doesn't move for some period
_this.$outer.on('mousemove.lg click.lg touchstart.lg', function() {
_this.$outer.removeClass('lg-hide-items');
clearTimeout(_this.hideBartimeout);
// Timeout will be cleared on each slide movement also
_this.hideBartimeout = setTimeout(function() {
_this.$outer.addClass('lg-hide-items');
}, _this.s.hideBarsDelay);
});
_this.$outer.trigger('mousemove.lg');
};
Plugin.prototype.structure = function() {
var list = '';
var controls = '';
var subHtmlCont = '';
var template;
var _this = this;
$('body').append('<div class="lg-backdrop"></div>');
$('.lg-backdrop').css('transition-duration', this.s.backdropDuration + 'ms');
// Create gallery items
for (var i = 0; i < this.$items.length; i++) {
list += '<div class="lg-item"></div>';
}
Plugin.prototype.isVideo = function(src, index) {
var html;
if (this.s.dynamic) {
html = this.s.dynamicEl[index].html;
} else {
html = this.$items.eq(index).attr('data-html');
}
if (!src) {
if(html) {
return {
html5: true
};
} else {
console.error('lightGallery :- data-src is not pvovided on slide item ' + (index + 1) + '. Please make sure the selector property is properly configured. More info - http://sachinchoolur.github.io/lightGallery/demos/html-markup.html');
return false;
}
}
var youtube = src.match(/\/\/(?:www\.)?youtu(?:\.be|be\.com|be-nocookie\.com)\/(?:watch\?v=|embed\/)?([a-z0-9\-\_\%]+)/i);
var vimeo = src.match(/\/\/(?:www\.)?vimeo.com\/([0-9a-z\-_]+)/i);
var dailymotion = src.match(/\/\/(?:www\.)?dai.ly\/([0-9a-z\-_]+)/i);
var vk = src.match(/\/\/(?:www\.)?(?:vk\.com|vkontakte\.ru)\/(?:video_ext\.php\?)(.*)/i);
if (youtube) {
return {
youtube: youtube
};
} else if (vimeo) {
return {
vimeo: vimeo
};
} else if (dailymotion) {
return {
dailymotion: dailymotion
};
} else if (vk) {
return {
vk: vk
};
}
};
/**
* #desc Create image counter
* Ex: 1/10
*/
Plugin.prototype.counter = function() {
if (this.s.counter) {
$(this.s.appendCounterTo).append('<div id="lg-counter"><span id="lg-counter-current">' + (parseInt(this.index, 10) + 1) + '</span> / <span id="lg-counter-all">' + this.$items.length + '</span></div>');
}
};
/**
* #desc add sub-html into the slide
* #param {Number} index - index of the slide
*/
Plugin.prototype.addHtml = function(index) {
var subHtml = null;
var subHtmlUrl;
var $currentEle;
if (this.s.dynamic) {
if (this.s.dynamicEl[index].subHtmlUrl) {
subHtmlUrl = this.s.dynamicEl[index].subHtmlUrl;
} else {
subHtml = this.s.dynamicEl[index].subHtml;
}
} else {
$currentEle = this.$items.eq(index);
if ($currentEle.attr('data-sub-html-url')) {
subHtmlUrl = $currentEle.attr('data-sub-html-url');
} else {
subHtml = $currentEle.attr('data-sub-html');
if (this.s.getCaptionFromTitleOrAlt && !subHtml) {
subHtml = $currentEle.attr('title') || $currentEle.find('img').first().attr('alt');
}
}
}
if (!subHtmlUrl) {
if (typeof subHtml !== 'undefined' && subHtml !== null) {
// get first letter of subhtml
// if first letter starts with . or # get the html form the jQuery object
var fL = subHtml.substring(0, 1);
if (fL === '.' || fL === '#') {
if (this.s.subHtmlSelectorRelative && !this.s.dynamic) {
subHtml = $currentEle.find(subHtml).html();
} else {
subHtml = $(subHtml).html();
}
}
} else {
subHtml = '';
}
}
if (this.s.appendSubHtmlTo === '.lg-sub-html') {
if (subHtmlUrl) {
this.$outer.find(this.s.appendSubHtmlTo).load(subHtmlUrl);
} else {
this.$outer.find(this.s.appendSubHtmlTo).html(subHtml);
}
} else {
if (subHtmlUrl) {
this.$slide.eq(index).load(subHtmlUrl);
} else {
this.$slide.eq(index).append(subHtml);
}
}
// Add lg-empty-html class if title doesn't exist
if (typeof subHtml !== 'undefined' && subHtml !== null) {
if (subHtml === '') {
this.$outer.find(this.s.appendSubHtmlTo).addClass('lg-empty-html');
} else {
this.$outer.find(this.s.appendSubHtmlTo).removeClass('lg-empty-html');
}
}
this.$el.trigger('onAfterAppendSubHtml.lg', [index]);
};
/**
* #desc Preload slides
* #param {Number} index - index of the slide
*/
Plugin.prototype.preload = function(index) {
var i = 1;
var j = 1;
for (i = 1; i <= this.s.preload; i++) {
if (i >= this.$items.length - index) {
break;
}
this.loadContent(index + i, false, 0);
}
for (j = 1; j <= this.s.preload; j++) {
if (index - j < 0) {
break;
}
this.loadContent(index - j, false, 0);
}
};
/**
* #desc Load slide content into slide.
* #param {Number} index - index of the slide.
* #param {Boolean} rec - if true call loadcontent() function again.
* #param {Boolean} delay - delay for adding complete class. it is 0 except first time.
*/
Plugin.prototype.loadContent = function(index, rec, delay) {
var _this = this;
var _hasPoster = false;
var _$img;
var _src;
var _poster;
var _srcset;
var _sizes;
var _html;
var getResponsiveSrc = function(srcItms) {
var rsWidth = [];
var rsSrc = [];
for (var i = 0; i < srcItms.length; i++) {
var __src = srcItms[i].split(' ');
// Manage empty space
if (__src[0] === '') {
__src.splice(0, 1);
}
rsSrc.push(__src[0]);
rsWidth.push(__src[1]);
}
var wWidth = $(window).width();
for (var j = 0; j < rsWidth.length; j++) {
if (parseInt(rsWidth[j], 10) > wWidth) {
_src = rsSrc[j];
break;
}
}
};
if (_this.s.dynamic) {
if (_this.s.dynamicEl[index].poster) {
_hasPoster = true;
_poster = _this.s.dynamicEl[index].poster;
}
_html = _this.s.dynamicEl[index].html;
_src = _this.s.dynamicEl[index].src;
if (_this.s.dynamicEl[index].responsive) {
var srcDyItms = _this.s.dynamicEl[index].responsive.split(',');
getResponsiveSrc(srcDyItms);
}
_srcset = _this.s.dynamicEl[index].srcset;
_sizes = _this.s.dynamicEl[index].sizes;
} else {
if (_this.$items.eq(index).attr('data-poster')) {
_hasPoster = true;
_poster = _this.$items.eq(index).attr('data-poster');
}
_html = _this.$items.eq(index).attr('data-html');
_src = _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src');
if (_this.$items.eq(index).attr('data-responsive')) {
var srcItms = _this.$items.eq(index).attr('data-responsive').split(',');
getResponsiveSrc(srcItms);
}
_srcset = _this.$items.eq(index).attr('data-srcset');
_sizes = _this.$items.eq(index).attr('data-sizes');
}
if (_src || _srcset || _sizes || _poster) {
var iframe = false;
if (_this.s.dynamic) {
if (_this.s.dynamicEl[index].iframe) {
iframe = true;
}
} else {
if (_this.$items.eq(index).attr('data-iframe') === 'true') {
iframe = true;
}
}
var _isVideo = _this.isVideo(_src, index);
if (!_this.$slide.eq(index).hasClass('lg-loaded')) {
if (iframe) {
_this.$slide.eq(index).prepend('<div class="lg-video-cont lg-has-iframe" style="max-width:' + _this.s.iframeMaxWidth + '"><div class="lg-video"><iframe class="lg-object" frameborder="0" src="' + _src + '" allowfullscreen="true"></iframe></div></div>');
} else if (_hasPoster) {
var videoClass = '';
if (_isVideo && _isVideo.youtube) {
videoClass = 'lg-has-youtube';
} else if (_isVideo && _isVideo.vimeo) {
videoClass = 'lg-has-vimeo';
} else {
videoClass = 'lg-has-html5';
}
_this.$slide.eq(index).prepend('<div class="lg-video-cont ' + videoClass + ' "><div class="lg-video"><span class="lg-video-play"></span><img class="lg-object lg-has-poster" src="' + _poster + '" /></div></div>');
} else if (_isVideo) {
_this.$slide.eq(index).prepend('<div class="lg-video-cont "><div class="lg-video"></div></div>');
_this.$el.trigger('hasVideo.lg', [index, _src, _html]);
} else {
_this.$slide.eq(index).prepend('<div class="lg-img-wrap"><img class="lg-object lg-image" src="' + _src + '" /></div>');
}
_this.$el.trigger('onAferAppendSlide.lg', [index]);
_$img = _this.$slide.eq(index).find('.lg-object');
if (_sizes) {
_$img.attr('sizes', _sizes);
}
if (_srcset) {
_$img.attr('srcset', _srcset);
try {
picturefill({
elements: [_$img[0]]
});
} catch (e) {
console.warn('lightGallery :- If you want srcset to be supported for older browser please include picturefil version 2 javascript library in your document.');
}
}
if (this.s.appendSubHtmlTo !== '.lg-sub-html') {
_this.addHtml(index);
}
_this.$slide.eq(index).addClass('lg-loaded');
}
_this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
// For first time add some delay for displaying the start animation.
var _speed = 0;
// Do not change the delay value because it is required for zoom plugin.
// If gallery opened from direct url (hash) speed value should be 0
if (delay && !$('body').hasClass('lg-from-hash')) {
_speed = delay;
}
setTimeout(function() {
_this.$slide.eq(index).addClass('lg-complete');
_this.$el.trigger('onSlideItemLoad.lg', [index, delay || 0]);
}, _speed);
});
// #todo check load state for html5 videos
if (_isVideo && _isVideo.html5 && !_hasPoster) {
_this.$slide.eq(index).addClass('lg-complete');
}
if (rec === true) {
if (!_this.$slide.eq(index).hasClass('lg-complete')) {
_this.$slide.eq(index).find('.lg-object').on('load.lg error.lg', function() {
_this.preload(index);
});
} else {
_this.preload(index);
}
}
}
};
Plugin.prototype.slide = function(index, fromTouch, fromThumb, direction) {
var _prevIndex = this.$outer.find('.lg-current').index();
var _this = this;
// Prevent if multiple call
// Required for hsh plugin
if (_this.lGalleryOn && (_prevIndex === index)) {
return;
}
var _length = this.$slide.length;
var _time = _this.lGalleryOn ? this.s.speed : 0;
if (!_this.lgBusy) {
if (this.s.download) {
var _src;
if (_this.s.dynamic) {
_src = _this.s.dynamicEl[index].downloadUrl !== false && (_this.s.dynamicEl[index].downloadUrl || _this.s.dynamicEl[index].src);
} else {
_src = _this.$items.eq(index).attr('data-download-url') !== 'false' && (_this.$items.eq(index).attr('data-download-url') || _this.$items.eq(index).attr('href') || _this.$items.eq(index).attr('data-src'));
}
if (_src) {
$('#lg-download').attr('href', _src);
_this.$outer.removeClass('lg-hide-download');
} else {
_this.$outer.addClass('lg-hide-download');
}
}
this.$el.trigger('onBeforeSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
_this.lgBusy = true;
clearTimeout(_this.hideBartimeout);
// Add title if this.s.appendSubHtmlTo === lg-sub-html
if (this.s.appendSubHtmlTo === '.lg-sub-html') {
// wait for slide animation to complete
setTimeout(function() {
_this.addHtml(index);
}, _time);
}
this.arrowDisable(index);
if (!direction) {
if (index < _prevIndex) {
direction = 'prev';
} else if (index > _prevIndex) {
direction = 'next';
}
}
if (!fromTouch) {
// remove all transitions
_this.$outer.addClass('lg-no-trans');
this.$slide.removeClass('lg-prev-slide lg-next-slide');
if (direction === 'prev') {
//prevslide
this.$slide.eq(index).addClass('lg-prev-slide');
this.$slide.eq(_prevIndex).addClass('lg-next-slide');
} else {
// next slide
this.$slide.eq(index).addClass('lg-next-slide');
this.$slide.eq(_prevIndex).addClass('lg-prev-slide');
}
// give 50 ms for browser to add/remove class
setTimeout(function() {
_this.$slide.removeClass('lg-current');
//_this.$slide.eq(_prevIndex).removeClass('lg-current');
_this.$slide.eq(index).addClass('lg-current');
// reset all transitions
_this.$outer.removeClass('lg-no-trans');
}, 50);
} else {
this.$slide.removeClass('lg-prev-slide lg-current lg-next-slide');
var touchPrev;
var touchNext;
if (_length > 2) {
touchPrev = index - 1;
touchNext = index + 1;
if ((index === 0) && (_prevIndex === _length - 1)) {
// next slide
touchNext = 0;
touchPrev = _length - 1;
} else if ((index === _length - 1) && (_prevIndex === 0)) {
// prev slide
touchNext = 0;
touchPrev = _length - 1;
}
} else {
touchPrev = 0;
touchNext = 1;
}
if (direction === 'prev') {
_this.$slide.eq(touchNext).addClass('lg-next-slide');
} else {
_this.$slide.eq(touchPrev).addClass('lg-prev-slide');
}
_this.$slide.eq(index).addClass('lg-current');
}
if (_this.lGalleryOn) {
setTimeout(function() {
_this.loadContent(index, true, 0);
}, this.s.speed + 50);
setTimeout(function() {
_this.lgBusy = false;
_this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
}, this.s.speed);
} else {
_this.loadContent(index, true, _this.s.backdropDuration);
_this.lgBusy = false;
_this.$el.trigger('onAfterSlide.lg', [_prevIndex, index, fromTouch, fromThumb]);
}
_this.lGalleryOn = true;
if (this.s.counter) {
$('#lg-counter-current').text(index + 1);
}
}
_this.index = index;
};
$(document).ready(function() {
for(var i=0; i<10 ; i++){
$('#lightgallery' + i).lightGallery({
pager: true
});
}
});
HTML:
<section id="galler" style="display: flex; flex-wrap: wrap; justify-content:center;">
<div class="demo-gallery">
<ul id="lightgallery0">
<h4>First love 29.07.2018.</h4>
<li data-responsive="img/29.07.2018/1.jpg 375, img/29.07.2018/1.jpg 480, img/29.07.2018/1.jpg 800" data-src="img/29.07.2018/1.jpg" data-sub-html="<h4>Solar Matinee - First Love</h4> " style='display:inline-block;' data-pinterest-text="Pin it">
<a href="">
<img class="img-responsive" src="img/29.07.2018/1.jpg">
<div class="demo-gallery-poster">
<img src="img/zoom.png">
</div>
</a>
</li>
<li data-responsive="img/29.07.2018/2.jpg 375, img/29.07.2018/2.jpg 800" class="none" data-src="img/29.07.2018/2.jpg" data-pinterest-text="Pin it">
</li>
<li data-responsive="img/29.07.2018/3.jpg 375, img/29.07.2018/3.jpg 800" class="none" data-src="img/29.07.2018/3.jpg" data-pinterest-text="Pin it">
</li>
</ul>
</div>
</section>
Your js script is missing some lines, to minimize the error possibility I called them over CDN and made little changes on your script. Have a look at snippet:
$(document).ready(function() {
$("[id^=lightgallery]").lightGallery({ /* no need to loop, just select elements which starting with "lightgallery" */
pager: true,
selector: 'li' /* we need to show which elements are our items (to not assume h4 as a slider item [reason of "data-src is not pvovided on slide item 1" error]) */
});
});
<!DOCTYPE html>
<html lang="en">
<head>
<link href="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.6.11/css/lightgallery.min.css" rel="stylesheet">
<style type="text/css">
body {
background-color: #152836
}
.demo-gallery>ul {
margin-bottom: 0;
}
.demo-gallery>ul>li {
float: left;
margin-bottom: 15px;
margin-right: 20px;
width: 200px;
}
.demo-gallery>ul>li a {
border: 3px solid #FFF;
border-radius: 3px;
display: block;
overflow: hidden;
position: relative;
float: left;
}
.demo-gallery>ul>li a>img {
-webkit-transition: -webkit-transform 0.15s ease 0s;
-moz-transition: -moz-transform 0.15s ease 0s;
-o-transition: -o-transform 0.15s ease 0s;
transition: transform 0.15s ease 0s;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
height: 100%;
width: 100%;
}
.demo-gallery>ul>li a:hover>img {
-webkit-transform: scale3d(1.1, 1.1, 1.1);
transform: scale3d(1.1, 1.1, 1.1);
}
.demo-gallery>ul>li a:hover .demo-gallery-poster>img {
opacity: 1;
}
.demo-gallery>ul>li a .demo-gallery-poster {
background-color: rgba(0, 0, 0, 0.1);
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
-webkit-transition: background-color 0.15s ease 0s;
-o-transition: background-color 0.15s ease 0s;
transition: background-color 0.15s ease 0s;
}
.demo-gallery>ul>li a .demo-gallery-poster>img {
left: 50%;
margin-left: -10px;
margin-top: -10px;
opacity: 0;
position: absolute;
top: 50%;
-webkit-transition: opacity 0.3s ease 0s;
-o-transition: opacity 0.3s ease 0s;
transition: opacity 0.3s ease 0s;
}
.demo-gallery>ul>li a:hover .demo-gallery-poster {
background-color: rgba(0, 0, 0, 0.5);
}
.demo-gallery .justified-gallery>a>img {
-webkit-transition: -webkit-transform 0.15s ease 0s;
-moz-transition: -moz-transform 0.15s ease 0s;
-o-transition: -o-transform 0.15s ease 0s;
transition: transform 0.15s ease 0s;
-webkit-transform: scale3d(1, 1, 1);
transform: scale3d(1, 1, 1);
height: 100%;
width: 100%;
}
.demo-gallery .justified-gallery>a:hover>img {
-webkit-transform: scale3d(1.1, 1.1, 1.1);
transform: scale3d(1.1, 1.1, 1.1);
}
.demo-gallery .justified-gallery>a:hover .demo-gallery-poster>img {
opacity: 1;
}
.demo-gallery .justified-gallery>a .demo-gallery-poster {
background-color: rgba(0, 0, 0, 0.1);
bottom: 0;
left: 0;
position: absolute;
right: 0;
top: 0;
-webkit-transition: background-color 0.15s ease 0s;
-o-transition: background-color 0.15s ease 0s;
transition: background-color 0.15s ease 0s;
}
.demo-gallery .justified-gallery>a .demo-gallery-poster>img {
left: 50%;
margin-left: -10px;
margin-top: -10px;
opacity: 0;
position: absolute;
top: 50%;
-webkit-transition: opacity 0.3s ease 0s;
-o-transition: opacity 0.3s ease 0s;
transition: opacity 0.3s ease 0s;
}
.demo-gallery .justified-gallery>a:hover .demo-gallery-poster {
background-color: rgba(0, 0, 0, 0.5);
}
.demo-gallery .video .demo-gallery-poster img {
height: 48px;
margin-left: -24px;
margin-top: -24px;
opacity: 0.8;
width: 48px;
}
.demo-gallery.dark>ul>li a {
border: 3px solid #04070a;
}
.home .demo-gallery {
padding-bottom: 80px;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
<body class="home">
<div class="demo-gallery">
<ul id="lightgallery0">
<h4>First love 29.07.2018.</h4>
<li data-src="https://dummyimage.com/600x400/000000/fff&text=1" data-sub-html="<h4>Solar Matinee - First Love</h4> " style='display:inline-block;' data-pinterest-text="Pin it">
<a href="">
<img class="img-responsive" src="https://dummyimage.com/600x400/000000/fff&text=1">
</a>
</li>
<li class="none" data-src="https://dummyimage.com/600x400/000000/fff&text=2" data-pinterest-text="Pin it">
<a href="">
<img class="img-responsive" src="https://dummyimage.com/600x400/000000/fff&text=2">
</a>
</li>
<li class="none" data-src="https://dummyimage.com/600x400/000000/fff&text=3" data-pinterest-text="Pin it">
<a href="">
<img class="img-responsive" src="https://dummyimage.com/600x400/000000/fff&text=3">
</a>
</li>
</ul>
</div>
<script src="https://cdn.jsdelivr.net/picturefill/2.3.1/picturefill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/lightgallery/1.6.11/js/lightgallery-all.js"></script>
</body>
</html>

React animate component when it render and when its state change

For animation i write the code like this but this code is not working for me. Whant to know this is a css problem or my code style needs update. or how to do animation on a component
render: function() {
var len = Object.keys(Interfaces.previewContainer.state.sourceImg).length;
var imgContainer = [];
for (var i = 0; i < len; i++) {
imgContainer.push(React.createElement(PreviewImgContainer, {
key: i,
flipParentClass: this.state.flipParentClass,
i_d: 'SelectedTemplate_' + i,
dataactionstring: 'selecttemplatetype-' + this.state.dataactionstring['src' + i],
sourceImg: this.state.sourceImg['src' + i],
ref: 'PreviewImgContainer',
alter: this.state.alter
}));
}
return (
React.createElement(
ReactCSSTransitionGroup, {
className:'flipParent',
transitionEnterTimeout: 250,
transitionLeaveTimeout: 250,
transitionName: 'flipped' // 'flipParent flipped' is a class name
},
React.createElement('div', {
className: 'previewContainer',
style: {
marginLeft: this.state.marginLeft
},
ref: 'previewContainer'
}, imgContainer)
)
);
}
please let me know where i am making a mistake or where i have to update the code
.flipParent {
height: 100%;
position: relative;
transform-style: preserve-3d;
transition: transform 0.5s ease 0s;
width: 100%;
}
/* .flipped is for flipping (x-axis) the element */
.flipped {
transform: rotateY(180deg);
}
Maybe you have to implement these
.flipped-enter
.flipped-enter.flipped-enter-active
.flipped-leave
.flipped-leave.flipped-leave-active
The below screenshot is from the official react guide

Resources