Last active
April 4, 2018 08:38
-
-
Save zdimaz/107dbc6c462ee363c6aff2c735bbabdd to your computer and use it in GitHub Desktop.
Аккордионы со скроллом
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
<dl class="accordion"> | |
<dt>Заголовок</dt> | |
<dd> | |
Контент | |
</dd> | |
<dt>Заголовок</dt> | |
<dd> | |
Контент | |
</dd> | |
<dt>Заголовок</dt> | |
<dd> | |
Контент | |
</dd> | |
</dl> | |
if($(".accordion").length){ | |
self.jqueryExtend(); | |
$(".accordion").accordion(); | |
} | |
jqueryExtend: function(){ | |
$.fn.extend({ | |
/** | |
** Accordion plugin | |
** @param toggle - set to true, if need to be toggle | |
** @return jQuery | |
**/ | |
accordion : function(toggle){ | |
return this.each(function(){ | |
var $this = $(this), | |
active = $this.children('dt.active').length ? $this.children('dt.active') : null; | |
$this.children('dt').not(active).next().hide(); | |
$this.on('click', 'dt', function(){ | |
var $this = $(this); | |
if(!toggle){ | |
if($(this).hasClass('active')){ | |
$(this).removeClass('active') | |
.siblings('dt') | |
.removeClass('active') | |
.end() | |
.siblings('dd') | |
.stop() | |
.slideUp(); | |
} | |
else{ | |
$(this).addClass('active') | |
.siblings('dt') | |
.removeClass('active') | |
.end() | |
.next('dd') | |
.stop() | |
.slideDown(500, function(){ | |
var offset = $this.next().offset().top, | |
headerH = $('#header').height(); | |
$("html").animate({ | |
'scrollTop': offset | |
},1000); | |
$("body").animate({ | |
'scrollTop': offset - headerH | |
},1000); | |
}) | |
.siblings('dd') | |
.stop() | |
.slideUp(); | |
} | |
} | |
else{ | |
$(this).toggleClass('active').next().stop().slideToggle(); | |
} | |
}); | |
}); | |
} | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment