How to reset SVG animation in owl-carousel
I have svg animation, made like this
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
JS for animating
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
setTimeout(draw, t); // Redraw
}());
and css
svg {
position: absolute;
top: 0;
border: 3px solid pink;
border-radius: 50px;
}
svg path {display: none;}
.owl-dot.active svg path {display: block;}
css is mainly for display swg when class active is setted. It is in carousel, so i need to display just one animation for each slide. But the problem is, that all svg are animating at the same time. I need to reset these animations everytime, when carousel change slide. For carousel is used Owl-Carousel with simple code :
$("#our-work-carousel2").owlCarousel({
loop: true,
lazyLoad: true,
autoplay: true,
animateIn: 'fadeIn',
animateOut: 'fadeOut',
slideSpeed: 300,
paginationSpeed: 400,
dotData: true,
dotsData: true,
itemsDesktop: false,
itemsDesktopSmall: false,
itemsTablet: true,
itemsMobile: false,
onChange:callback,
});
function callback(event){
}
I would probably need some code in callback for reset svg animation, but i can´t figure out this solution. Thanks to all for every advice.
javascript html svg owl-carousel owl-carousel-2
add a comment |
I have svg animation, made like this
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
JS for animating
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
setTimeout(draw, t); // Redraw
}());
and css
svg {
position: absolute;
top: 0;
border: 3px solid pink;
border-radius: 50px;
}
svg path {display: none;}
.owl-dot.active svg path {display: block;}
css is mainly for display swg when class active is setted. It is in carousel, so i need to display just one animation for each slide. But the problem is, that all svg are animating at the same time. I need to reset these animations everytime, when carousel change slide. For carousel is used Owl-Carousel with simple code :
$("#our-work-carousel2").owlCarousel({
loop: true,
lazyLoad: true,
autoplay: true,
animateIn: 'fadeIn',
animateOut: 'fadeOut',
slideSpeed: 300,
paginationSpeed: 400,
dotData: true,
dotsData: true,
itemsDesktop: false,
itemsDesktopSmall: false,
itemsTablet: true,
itemsMobile: false,
onChange:callback,
});
function callback(event){
}
I would probably need some code in callback for reset svg animation, but i can´t figure out this solution. Thanks to all for every advice.
javascript html svg owl-carousel owl-carousel-2
add a comment |
I have svg animation, made like this
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
JS for animating
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
setTimeout(draw, t); // Redraw
}());
and css
svg {
position: absolute;
top: 0;
border: 3px solid pink;
border-radius: 50px;
}
svg path {display: none;}
.owl-dot.active svg path {display: block;}
css is mainly for display swg when class active is setted. It is in carousel, so i need to display just one animation for each slide. But the problem is, that all svg are animating at the same time. I need to reset these animations everytime, when carousel change slide. For carousel is used Owl-Carousel with simple code :
$("#our-work-carousel2").owlCarousel({
loop: true,
lazyLoad: true,
autoplay: true,
animateIn: 'fadeIn',
animateOut: 'fadeOut',
slideSpeed: 300,
paginationSpeed: 400,
dotData: true,
dotsData: true,
itemsDesktop: false,
itemsDesktopSmall: false,
itemsTablet: true,
itemsMobile: false,
onChange:callback,
});
function callback(event){
}
I would probably need some code in callback for reset svg animation, but i can´t figure out this solution. Thanks to all for every advice.
javascript html svg owl-carousel owl-carousel-2
I have svg animation, made like this
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
JS for animating
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
setTimeout(draw, t); // Redraw
}());
and css
svg {
position: absolute;
top: 0;
border: 3px solid pink;
border-radius: 50px;
}
svg path {display: none;}
.owl-dot.active svg path {display: block;}
css is mainly for display swg when class active is setted. It is in carousel, so i need to display just one animation for each slide. But the problem is, that all svg are animating at the same time. I need to reset these animations everytime, when carousel change slide. For carousel is used Owl-Carousel with simple code :
$("#our-work-carousel2").owlCarousel({
loop: true,
lazyLoad: true,
autoplay: true,
animateIn: 'fadeIn',
animateOut: 'fadeOut',
slideSpeed: 300,
paginationSpeed: 400,
dotData: true,
dotsData: true,
itemsDesktop: false,
itemsDesktopSmall: false,
itemsTablet: true,
itemsMobile: false,
onChange:callback,
});
function callback(event){
}
I would probably need some code in callback for reset svg animation, but i can´t figure out this solution. Thanks to all for every advice.
javascript html svg owl-carousel owl-carousel-2
javascript html svg owl-carousel owl-carousel-2
asked Nov 19 '18 at 11:19
kores59kores59
927
927
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
The animation state is updated based on the variable a
, on each step of the animation the variable is increased by one, until reaching 360, then return to 0.
To reset the animation you need to reset the variable a
setting the value 0.
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373518%2fhow-to-reset-svg-animation-in-owl-carousel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The animation state is updated based on the variable a
, on each step of the animation the variable is increased by one, until reaching 360, then return to 0.
To reset the animation you need to reset the variable a
setting the value 0.
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
add a comment |
The animation state is updated based on the variable a
, on each step of the animation the variable is increased by one, until reaching 360, then return to 0.
To reset the animation you need to reset the variable a
setting the value 0.
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
add a comment |
The animation state is updated based on the variable a
, on each step of the animation the variable is increased by one, until reaching 360, then return to 0.
To reset the animation you need to reset the variable a
setting the value 0.
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
The animation state is updated based on the variable a
, on each step of the animation the variable is increased by one, until reaching 360, then return to 0.
To reset the animation you need to reset the variable a
setting the value 0.
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
var loader = document.getElementsByClassName("loader")
, a = 0
, p = Math.PI
, t = 9;
(function draw() {
a++;
a %= 360;
var r = ( a * p / 180 )
, x = Math.sin( r ) * 125
, y = Math.cos( r ) * - 125
, mid = ( a > 180 ) ? 1 : 0
, anim = "M 0 0 v -125 A 125 125 1 "
+ mid + " 1 "
+ x + " "
+ y + " z";
Object.values(loader).forEach(item=>item.setAttribute("d",anim));
console.log('a:', a);
setTimeout(draw, t); // Redraw
}());
document.getElementById('reset-loader').addEventListener('click', () => a = 0);
svg {
border: 3px solid pink;
border-radius: 50px;
}
<svg version='1.1' xmlns='http://www.w3.org/2000/svg'
xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' width='16'
height='16' viewbox='0 0 250 250' enable-background='new 0 0 426.667 410'
xml:space='preserve'><path class='loader' transform='translate(125, 125)
scale(.84)'/>
</svg>
<button id="reset-loader">reset</button>
answered Nov 19 '18 at 11:55
Santiago PernigottiSantiago Pernigotti
1315
1315
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
add a comment |
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
You are awesome. Thank you so much!
– kores59
Nov 19 '18 at 13:05
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53373518%2fhow-to-reset-svg-animation-in-owl-carousel%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown