Skip to content

Instantly share code, notes, and snippets.

@minwe
Created November 28, 2013 03:28
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 minwe/7686857 to your computer and use it in GitHub Desktop.
Save minwe/7686857 to your computer and use it in GitHub Desktop.
maybe
define(function (require, exports, module) {
var $ = Zepto;
/**
* slideToggle
* @param element
* @param display
*/
var slideToggleTrans = function (element, display, callback) { // display表示默认更多展开元素是显示状态还是隐藏
element.on("click", function () {
display = !display;
var rel = $(this).attr("data-rel"), eleMore = $("#" + rel);
eleMore.length > 0 && (eleMore.style.height = display ? (function () {
var height = 0;
Array.prototype.slice.call(eleMore.childNodes).forEach(function (child) {
if (child.nodeType === 1) {
var oStyle = window.getComputedStyle(child);
height = child.clientHeight + (parseInt(oStyle.borderTopWidth) || 0) + (parseInt(oStyle.borderBottomWidth) || 0);
}
});
return height;
})() + "px" : "0px");
callback.call(element, eleMore, display);
});
};
(function ($) {
$.fn.slideDown = function (duration) {
// get old position to restore it then
var position = this.css('position');
// show element if it is hidden (it is needed if display is none)
this.show();
// place it so it displays as usually but hidden
this.css({
position: 'absolute',
visibility: 'hidden'
});
// get naturally height
var height = this.height();
// set initial css for animation
this.css({
position: position,
visibility: 'visible',
overflow: 'hidden',
height: 0
});
// animate to gotten height
this.animate({
height: height
}, duration);
};
})(Zepto);
/* $(function () {
var menuParentItems = $(".am-menu .am-parent > a");
menuParentItems.on("click", function (e) {
e.preventDefault();
var subMenu = $(this).next(".am-menu-sub");
var parentItem = $(this).parent(".am-parent");
parentItem.toggleClass("am-active").find(".am-active").removeClass("am-active");
parentItem.siblings().removeClass("am-active");
});
});*/
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment