Skip to content

Commit 3c5eff6

Browse files
committed
Updated so the data-transition css selector is no longer needed
1 parent 0018fba commit 3c5eff6

File tree

7 files changed

+19
-40
lines changed

7 files changed

+19
-40
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ the ```data-transition``` attribute on each element that you wish to animate.
4343
</header>
4444
<div id="barba-wrapper">
4545
<div class="barba-container">
46-
<section class="all-posts" data-transition="fadein">
46+
<section class="all-posts" data-transition="fadeIn">
4747
This is the main page content
4848
</section>
4949
</div>
@@ -64,10 +64,6 @@ the ```data-transition``` attribute on each element that you wish to animate.
6464
0% {opacity: 0;}
6565
100% {opacity: 1;}
6666
}
67-
68-
[data-transition=fadein] {
69-
animation-name: fadeIn;
70-
}
7167
```
7268

7369
### JS

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<header><h1><a href="/index.html">My Blog</a></h1></header>
1010
<div id="barba-wrapper">
1111
<div class="barba-container">
12-
<section class="all-posts" data-transition="fadein">
12+
<section class="all-posts" data-transition="fadeIn">
1313
<ul>
1414
<li><a href="post.html">Post 1</a></li>
1515
<li><a href="post.html">Post 2</a></li>

example/post.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<header><h1><a href="index.html">My Blog</a></h1></header>
1010
<div id="barba-wrapper">
1111
<div class="barba-container">
12-
<section class="sidebar" data-transition="slideinright">
12+
<section class="sidebar" data-transition="slideInRight">
1313
Hello, I am the sidebar
1414
</section>
15-
<section class="post" data-transition="fadeinup">
15+
<section class="post" data-transition="fadeInUp">
1616
<h2>My Post Title</h2>
1717
<div class="content">
1818
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa. Vestibulum lacinia arcu eget nulla. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. </p>
@@ -31,7 +31,7 @@ <h2>My Post Title</h2>
3131

3232
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js" type="text/javascript"></script>
3333
<script src="https://rawgit.com/luruke/barba.js/master/dist/barba.min.js" type="text/javascript"></script>
34-
<script src="barba.transitions.js" type="text/javascript"></script>
34+
<script src="temp/barba.transitions.min.js" type="text/javascript"></script>
3535
<script src="main.js" type="text/javascript"></script>
3636
</body>
3737
</html>

example/style.css

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,3 @@ section.sidebar {
4747
0% {opacity: 0; transform: translate3d(-100%, 0, 0);}
4848
100% {opacity: 1; transform: none;}
4949
}
50-
51-
[data-transition=fadein] {
52-
animation-name: fadeIn;
53-
}
54-
55-
[data-transition=fadeinup] {
56-
animation-name: fadeInUp;
57-
}
58-
59-
[data-transition=slideinright] {
60-
animation-name: slideInRight;
61-
}

gulpfile.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ gulp.task('js-dev', function(){
5252

5353
gulp.task('watch', function() {
5454

55-
gulp.watch('src/**/*.js', ['js']);
55+
gulp.watch('src/**/*.js', ['js-dev']);
5656

5757
});
5858

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "barba-transitions",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "An addon to BarbaJS which makes it really easy to use css transitions for page transitions.",
55
"main": "barba.transitions.js",
66
"directories": {

src/transition.js

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,28 @@ var Transition = Barba.BaseTransition.extend({
1515
// Setup
1616
////////////////////////////
1717
var transitionLength = parseInt(Barba.transitionLength),
18-
transitionTimeout = 50,
18+
transitionTimeout = 100,
1919
transitionLengthSeconds = (transitionLength / 1000) + 's',
2020
transitionSelector = 'data-transition';
2121
////////////////////////////
2222

2323
// Set the animation time on all elements
2424
var allAnimationElements = $('[' + transitionSelector + ']');
2525
$.each(allAnimationElements, function() {
26-
$(this).css('animation-duration', transitionLengthSeconds).css('animation-delay', transitionLengthSeconds);
26+
$(this).css('animation-duration', transitionLengthSeconds).css('animation-delay', transitionLengthSeconds).css('animation-name', $(this).data('transition')).css('animation-fill-mode', 'forwards');
2727
})
2828

2929
// Get all old elements with transitions
30-
var cashEl = $(this.oldContainer),
31-
allTransitions = cashEl.find('[' + transitionSelector + ']'),
32-
transitions = [];
33-
34-
$.each(allTransitions, function() {
35-
x = {};
36-
x['transition'] = $(this).attr(transitionSelector);
37-
$(this).removeAttr(transitionSelector).css('animation-direction', 'alternate-reverse').css('animation-delay', '0s');
38-
x['element'] = $(this);
39-
transitions.push(x);
30+
var oldElements = $(this.oldContainer).find('[' + transitionSelector + ']');
31+
$.each(oldElements, function() {
32+
$(this).removeAttr('style');
4033
});
4134

42-
// Trigger transitions
35+
// Trigger out transitions
4336
setTimeout(function(){
44-
for (var i = 0; i < transitions.length; i++) {
45-
var el = transitions[i];
46-
el['element'].attr(transitionSelector, el['transition']);
47-
}
37+
$.each(oldElements, function() {
38+
$(this).css('animation-duration', transitionLengthSeconds).css('animation-delay', transitionLengthSeconds).css('animation-name', $(this).data('transition')).css('animation-direction', 'alternate-reverse').css('animation-delay', '0s').css('animation-fill-mode', 'forwards');
39+
});
4840
}, transitionTimeout);
4941

5042
var x = this;
@@ -55,6 +47,9 @@ var Transition = Barba.BaseTransition.extend({
5547
x.newContainer.style.visibility = 'visible';
5648
setTimeout(function(){
5749
$('body').css('overflow', 'visible');
50+
$.each(allAnimationElements, function() {
51+
$(this).removeAttr('style');
52+
});
5853
}, transitionLength);
5954

6055
// Scroll to top

0 commit comments

Comments
 (0)