Skip to content

Instantly share code, notes, and snippets.

@joshycube
Created November 4, 2014 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshycube/de12e5793e70a4de71ce to your computer and use it in GitHub Desktop.
Save joshycube/de12e5793e70a4de71ce to your computer and use it in GitHub Desktop.
<style id="jsbin-css">
.slider li{ display: none; }
.active-slide { display: inline!important; }
</style>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<!-- slider 1 -->
<div class="slider-item-one">
<ul class="slider">
<li class="active-slide">content 1</li>
<li>content 2</li>
<li>content 3</li>
<li>content 4</li>
</ul>
<a data-dir="bwd" class="step">Backward</a>
<a data-dir="fwd" class="step">Forward</a>
</div>
<!-- slider 2 -->
<div class="slider-item-two">
<ul class="slider">
<li class="active-slide">content 1</li>
<li>content 2</li>
<li>content 3</li>
<li>content 4</li>
</ul>
<a data-dir="bwd" class="step">Backward</a>
<a data-dir="fwd" class="step">Forward</a>
</div>
<script id="jsbin-javascript">
// Ez a jQuery plugin ami magaba foglalja a slidert
;(function ( $, window, document, undefined ) {
var pluginName = "codeGarageSliders",
defaults = {
controlClass: ".step",
};
function Plugin ( element, options ) {
this.element = element;
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
var context = this,
$ctrl = $(this.element).find(this.settings.controlClass),
sliderLt = $(this.element).find('.slider > li').length;
$ctrl.on('click', function() {
var dir = $(this).data('dir');
context.moveSlider(dir, sliderLt);
});
},
moveSlider: function(dir, sliderLt) {
var act = $(this.element).find('.active-slide').index()+1,
$el = $(this.element);
if(dir == 'fwd') {
var next = act+1;
next = (next > sliderLt) ? 1 : next;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+next+')', $el).show(800).addClass('active-slide');
}
if(dir == 'bwd') {
var prev = act-1;
prev = (prev === 0) ? sliderLt : prev;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+prev+')', $el).show(800).addClass('active-slide');
}
}
});
$.fn[ pluginName ] = function ( options ) {
this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
return this;
};
})( jQuery, window, document );
//Igy kell futtatni
(function($) {
$('.slider-item-one').codeGarageSliders({
controlClass: '.step'
});
$('.slider-item-two').codeGarageSliders({
controlClass: '.step'
});
}(jQuery));
</script>
<script id="jsbin-source-html" type="text/html"><script src="//code.jquery.com/jquery-1.9.1.min.js"><\/script>
<\!-- slider 1 -->
<div class="slider-item-one">
<ul class="slider">
<li class="active-slide">content 1</li>
<li>content 2</li>
<li>content 3</li>
<li>content 4</li>
</ul>
<a data-dir="bwd" class="step">Backward</a>
<a data-dir="fwd" class="step">Forward</a>
</div>
<\!-- slider 2 -->
<div class="slider-item-two">
<ul class="slider">
<li class="active-slide">content 1</li>
<li>content 2</li>
<li>content 3</li>
<li>content 4</li>
</ul>
<a data-dir="bwd" class="step">Backward</a>
<a data-dir="fwd" class="step">Forward</a>
</div>
</script>
<script id="jsbin-source-css" type="text/css">.slider li{ display: none; }
.active-slide { display: inline!important; }</script>
<script id="jsbin-source-javascript" type="text/javascript">// Ez a jQuery plugin ami magaba foglalja a slidert
;(function ( $, window, document, undefined ) {
var pluginName = "codeGarageSliders",
defaults = {
controlClass: ".step",
};
function Plugin ( element, options ) {
this.element = element;
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
var context = this,
$ctrl = $(this.element).find(this.settings.controlClass),
sliderLt = $(this.element).find('.slider > li').length;
$ctrl.on('click', function() {
var dir = $(this).data('dir');
context.moveSlider(dir, sliderLt);
});
},
moveSlider: function(dir, sliderLt) {
var act = $(this.element).find('.active-slide').index()+1,
$el = $(this.element);
if(dir == 'fwd') {
var next = act+1;
next = (next > sliderLt) ? 1 : next;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+next+')', $el).show(800).addClass('active-slide');
}
if(dir == 'bwd') {
var prev = act-1;
prev = (prev === 0) ? sliderLt : prev;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+prev+')', $el).show(800).addClass('active-slide');
}
}
});
$.fn[ pluginName ] = function ( options ) {
this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
return this;
};
})( jQuery, window, document );
//Igy kell futtatni
(function($) {
$('.slider-item-one').codeGarageSliders({
controlClass: '.step'
});
$('.slider-item-two').codeGarageSliders({
controlClass: '.step'
});
}(jQuery));</script>
.slider li{ display: none; }
.active-slide { display: inline!important; }
// Ez a jQuery plugin ami magaba foglalja a slidert
;(function ( $, window, document, undefined ) {
var pluginName = "codeGarageSliders",
defaults = {
controlClass: ".step",
};
function Plugin ( element, options ) {
this.element = element;
this.settings = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
$.extend(Plugin.prototype, {
init: function () {
var context = this,
$ctrl = $(this.element).find(this.settings.controlClass),
sliderLt = $(this.element).find('.slider > li').length;
$ctrl.on('click', function() {
var dir = $(this).data('dir');
context.moveSlider(dir, sliderLt);
});
},
moveSlider: function(dir, sliderLt) {
var act = $(this.element).find('.active-slide').index()+1,
$el = $(this.element);
if(dir == 'fwd') {
var next = act+1;
next = (next > sliderLt) ? 1 : next;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+next+')', $el).show(800).addClass('active-slide');
}
if(dir == 'bwd') {
var prev = act-1;
prev = (prev === 0) ? sliderLt : prev;
$el.find('li:nth-child('+act+')', $el).hide(800).removeClass('active-slide');
$el.find('li:nth-child('+prev+')', $el).show(800).addClass('active-slide');
}
}
});
$.fn[ pluginName ] = function ( options ) {
this.each(function() {
if ( !$.data( this, "plugin_" + pluginName ) ) {
$.data( this, "plugin_" + pluginName, new Plugin( this, options ) );
}
});
return this;
};
})( jQuery, window, document );
//Igy kell futtatni
(function($) {
$('.slider-item-one').codeGarageSliders({
controlClass: '.step'
});
$('.slider-item-two').codeGarageSliders({
controlClass: '.step'
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment