Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function($){
- var items;
- var settings;
- var firstIndex;
- var lastIndex;
- var currentIndex;
- var self = this;
- var tempMap;
- var firstSlide = true;
- var cssObj;
- var methods = {
- init : function( options ) {
- var settings = $.extend( {
- 'firstIndex' : 0,
- 'duration' : 5000,
- 'cssPath' : 'css/slider.css',
- }, options);
- self.settings = settings;
- self.items = $(this).children();
- self.tempMap = {};
- var cssObj;
- $.get(self.settings.cssPath, function(cssContent){
- $.parsecss(cssContent, function(css){
- cssObj = css;
- });
- });
- console.log(cssObj);
- methods.createMap();
- methods.slideElement();
- },
- parseCss : function(cssContent){
- $.parsecss(cssContent, methods.setCssObj);
- },
- setCssObj : function(css){
- self.cssObj = 'asd';
- },
- createMap : function() {
- self.firstIndex = self.settings.firstIndex;
- self.currentIndex = self.settings.firstIndex;
- self.lastIndex = self.items.length;
- },
- slideElement : function( ) {
- if(self.currentIndex == self.lastIndex )
- self.currentIndex = self.firstIndex;
- self.items.eq(self.currentIndex).css('z-index', 1);
- self.items.eq(self.currentIndex - 1).css('z-index', 2);
- self.items.eq(self.currentIndex).children().each(function(index) {
- if(self.tempMap[self.currentIndex + '-' + index + 'animate-in'] == undefined){
- var tempElement = $(this).clone();
- tempElement.addClass('animate-in');
- self.tempMap[self.currentIndex + '-' + index + 'animate-in'] = tempElement;
- }
- if(self.tempMap[self.currentIndex + '-' + index + 'animate-out'] == undefined){
- var tempElement = $(this).clone();
- tempElement.addClass('animate-out');
- self.tempMap[self.currentIndex + '-' + index + 'animate-out'] = tempElement;
- }
- var delay = parseInt(self.tempMap[self.currentIndex + '-' + index + 'animate-in'].css('transition-duration')) * 1000;
- className = '.'+$(this).attr('class').replace(' ', '.');
- //console.log(self.cssObj);
- $(this).removeClass('animate-in');
- $(this).removeClass('animate-out');
- $(this).css('transition-duration', '0s');
- $(this).addClass('animate-in', delay);
- });
- if(self.firstSlide == false){
- var animateOutIndex = self.currentIndex == 0 ? self.lastIndex - 1 : self.currentIndex - 1;
- self.items.eq(animateOutIndex).children().each(function(index) {
- var delay = parseInt(self.tempMap[animateOutIndex + '-' + index + 'animate-out'].css('transition-duration')) * 1000;
- $(this).css('transition-duration', '0s');
- $(this).addClass('animate-out', delay);
- });
- }
- self.currentIndex++;
- self.firstSlide = false;
- var p = setTimeout ( methods.slideElement, self.settings.duration );
- },
- };
- $.fn.cssSlider = function( method ) {
- if ( methods[method] ) {
- return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.cssSlider' );
- }
- };
- })(jQuery);
Add Comment
Please, Sign In to add comment