Skip to content

Commit

Permalink
Optimize code.
Browse files Browse the repository at this point in the history
  • Loading branch information
panteng committed Jun 2, 2016
1 parent 1e100d4 commit 269a3b1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 60 deletions.
4 changes: 2 additions & 2 deletions app/src/javascripts/animation-control.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var $ = jQuery = require('jquery');
var $ = require('jquery');

module.exports = {
initAnimationItems: function() {
Expand Down Expand Up @@ -39,4 +39,4 @@ module.exports = {
$(this).attr('class', $(this).data('origin-class'));
});
}
}
};
118 changes: 60 additions & 58 deletions app/src/javascripts/main.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,68 @@
'use strict';
(function () {
'use strict';

// load dependencies
var animationControl = require('./animation-control.js');
// load dependencies
var animationControl = require('./animation-control.js');


$(document).ready(function () {
var bgMusic = $('audio').get(0);
var $btnMusic = $('.btn-music');
var $btnSwipe = $('.btn-swipe');
$(document).ready(function () {
var bgMusic = $('audio').get(0);
var $btnMusic = $('.btn-music');
var $btnSwipe = $('.btn-swipe');

// background music control
$btnMusic.click(function () {
if (bgMusic.paused) {
bgMusic.play();
$(this).removeClass('paused');
} else {
bgMusic.pause();
$(this).addClass('paused');
}
});

// init Swiper
new Swiper('.swiper-container', {
mousewheelControl: true,
effect: 'coverflow', // slide, fade, coverflow or flip
speed: 400,
direction: 'vertical',
fade: {
crossFade: false
},
coverflow: {
rotate: 100,
stretch: 0,
depth: 300,
modifier: 1,
slideShadows: false // do disable shadows for better performance
},
flip: {
limitRotation: true,
slideShadows: false // do disable shadows for better performance
},
onInit: function (swiper) {
animationControl.initAnimationItems(); // get items ready for animations
animationControl.playAnimation(swiper); // play animations of the first slide
},
onTransitionStart: function (swiper) { // on the last slide, hide .btn-swipe
if (swiper.activeIndex === swiper.slides.length - 1) {
$btnSwipe.hide();
// background music control
$btnMusic.click(function () {
if (bgMusic.paused) {
bgMusic.play();
$(this).removeClass('paused');
} else {
$btnSwipe.show();
bgMusic.pause();
$(this).addClass('paused');
}
},
onTransitionEnd: function (swiper) { // play animations of the current slide
animationControl.playAnimation(swiper);
},
onTouchStart: function (swiper, event) { // mobile devices don't allow audios to play automatically, it has to be triggered by a user event(click / touch).
if (!$btnMusic.hasClass('paused') && bgMusic.paused) {
bgMusic.play();
});

// init Swiper
new Swiper('.swiper-container', {
mousewheelControl: true,
effect: 'coverflow', // slide, fade, coverflow or flip
speed: 400,
direction: 'vertical',
fade: {
crossFade: false
},
coverflow: {
rotate: 100,
stretch: 0,
depth: 300,
modifier: 1,
slideShadows: false // do disable shadows for better performance
},
flip: {
limitRotation: true,
slideShadows: false // do disable shadows for better performance
},
onInit: function (swiper) {
animationControl.initAnimationItems(); // get items ready for animations
animationControl.playAnimation(swiper); // play animations of the first slide
},
onTransitionStart: function (swiper) { // on the last slide, hide .btn-swipe
if (swiper.activeIndex === swiper.slides.length - 1) {
$btnSwipe.hide();
} else {
$btnSwipe.show();
}
},
onTransitionEnd: function (swiper) { // play animations of the current slide
animationControl.playAnimation(swiper);
},
onTouchStart: function (swiper, event) { // mobile devices don't allow audios to play automatically, it has to be triggered by a user event(click / touch).
if (!$btnMusic.hasClass('paused') && bgMusic.paused) {
bgMusic.play();
}
}
}
});
});

// hide loading animation since everything is ready
$('.loading-overlay').slideUp();
});
// hide loading animation since everything is ready
$('.loading-overlay').slideUp();
});
})();

0 comments on commit 269a3b1

Please sign in to comment.