尝试创建一个可重复使用的手风琴功能,该功能需要3个参数:
active
类的元素参数#1 会根据屏幕尺寸而改变。我目前正在参数#3 进行undefined
注销。
var touchClick = "click",
touchDown = "mousedown",
rankingObject,
isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
if ("ontouchstart" in document.documentElement) {
touchClick = "touchend";
touchDown = "touchstart";
}
if (window.navigator.pointerEnabled) {
touchClick = "pointerup";
touchDown = "pointerdown";
}
function accordian(clickMe, addActive, animateMe) {
clickMe = $(clickMe).attr('class');
addActive = $(addActive).attr('class');
animateMe = $(addActive).find(animateMe).attr('class');
console.log(clickMe);
console.log(addActive);
console.log(animateMe);
clickMe.on(touchClick, function () {
if (addActive.hasClass('active')) {
addActive.find(animateMe).slideUp('fast');
addActive.removeClass('active');;
return false;
}
addActive.each(function () {
addActive.removeClass('active');
addActive.find(animateMe).slideDown('fast');
});
addActive.find(animateMe).slideDown('fast');
addActive.addClass('active');
});
}
$(window).on('load resize', function() {
if ($(window).width() < 769) {
$('.small_button').on(touchClick, function () {
var clicked = $(this);
var active = $('.wrap');
var animate = $('.wrap .info');
accordian(clicked, active, animate);
});
} else {
$('.large_button').on(touchClick, function () {
var clicked = $(this);
var active = $('.wrap');
var animate = $('.wrap .info');
accordian(clicked, active, animate);
});
}
});
答案 0 :(得分:0)
这可能不会完全回答你的问题但是因为我之前回答了类似的问题,我想我会引起你的注意:
只需4行代码即可轻松完成此任务。
$("[data-toggle='slider']").click( function(e) {
var next_of_kin = "[data-parent='" + e.target.id + "']";
$(next_of_kin).toggleClass('close');
});
您所要做的就是制作适当的“关闭”类,并在需要时分配数据父级和数据切换属性。
看到这个小提琴:http://jsfiddle.net/JA7qY/