Created
September 20, 2013 13:36
-
-
Save genoma/6637670 to your computer and use it in GitHub Desktop.
Slider Responsive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reference jQuery | |
$ = jQuery | |
# Adds plugin object to jQuery | |
$.fn.extend | |
# Change pluginName to your plugin's name. | |
responsiveSlider: (options) -> | |
# Default settings | |
settings = | |
debug: false | |
timing: 600 | |
# Merge default settings with options. | |
settings = $.extend settings, options | |
# Simple logger. | |
log = (msg) -> | |
console?.log msg if settings.debug | |
# Plugin start | |
return @each ()-> | |
#variables fpor classes | |
$this = $(this) | |
_s_button = $('.smart_button', this) | |
_s_slider = $('.smart_slider', this) | |
_s_li = $('.smart_button li', this) | |
_s_li_s = $('.smart_slider li', this) | |
#variables for generated classes | |
_index_a = 0; | |
_index_b = 0; | |
_s_button_number = $('li', _s_button).size() | |
_s_slider_number = $('li', _s_slider).size() | |
$(_s_li).each -> | |
_index_a += 1 | |
$(@).addClass '_b_'+_index_a | |
return | |
$(_s_li_s).each -> | |
_index_b += 1 | |
$(@).addClass '_s_'+_index_b | |
return | |
checkElement = (element) -> | |
_clicked_button = $(element).attr 'class' | |
_clicked_reference = _clicked_button.slice(-1) | |
_respect_window = '_s_' + _clicked_reference | |
openClose = (theClass) -> | |
$(_s_li_s).css | |
'position': 'absolute' | |
'z-index': '1' | |
$('li', _s_slider).animate | |
'opacity': '0' | |
, | |
duration: settings.timing | |
queue: false | |
$('.smart_slider li' + theClass, $this).css | |
'position': 'relative' | |
'z-index': '2' | |
$('.smart_slider li' + theClass, $this).animate | |
'opacity': '1' | |
, | |
duration: settings.timing | |
queue: false | |
return | |
$(_s_li).on 'click', -> | |
$(_s_li).attr 'id', '' | |
$(this).attr 'id', 'active' | |
thisElement = checkElement $(this) | |
#log thisElement | |
openClose '.' + thisElement | |
return | |
return # return the last function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment