cross.ui.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* ========================================================================
  2. * menu-collapse
  3. * ======================================================================== */
  4. +function ($) {
  5. $.fn.menucollapse = function (){
  6. var $this = $(this),
  7. $a = $this.find('li>a');
  8. $a.on('click',function(){
  9. $this.find('a').removeClass('curr');
  10. $(this).addClass('curr');
  11. var $arrow=$(this).find('span.arrow'),
  12. $ul=$(this).parent().children('ul.sub-menu');
  13. if($ul.length>0){
  14. if($ul.css('display')=="none"){
  15. $ul.slideDown();
  16. $arrow.html('<i class="iconfont">&#xe60e;</i>');
  17. }else{
  18. $ul.slideUp();
  19. $arrow.html('<i class="iconfont">&#xe60f;</i>');
  20. }
  21. }
  22. });
  23. }
  24. $('div[data-nav="menu"]').menucollapse();
  25. }(jQuery);
  26. /* ========================================================================
  27. * tabs
  28. * ======================================================================== */
  29. +(function($){
  30. $.fn.tabs=function(options){
  31. if(this.length == 0) return this;
  32. if(this.length > 1){
  33. this.each(function(){$(this).tabs(options)});
  34. return this;
  35. }
  36. if($(this).data('binds')=='yes') return false;
  37. $(this).data('binds','yes');
  38. var defaults={};
  39. var opts=$.extend(defaults,options || {});
  40. var $this=$(this),
  41. $hd=$this.children('div.tabs-hd').children('a'),
  42. $bd=$this.children('div.tabs-bd').children('div.tabs-bd-box');
  43. $hd.on('click',function(){
  44. var $el=$(this),
  45. index=$el.index();
  46. $el.addClass('curr').siblings().removeClass('curr');
  47. $bd.eq(index).addClass('curr').siblings().removeClass('curr');
  48. if(opts.callback){
  49. opts.callback(index);
  50. }
  51. })
  52. }
  53. })(jQuery);
  54. //函数节流
  55. function throttle(fn, delay){
  56. var timer = null;
  57. return function(){
  58. var context = this, args = arguments;
  59. clearTimeout(timer);
  60. timer = setTimeout(function(){
  61. fn.apply(context, args);
  62. }, delay);
  63. };
  64. };