JAVASCRIPT   68

switch js

Guest on 22nd June 2022 02:36:55 PM

  1. // 获取开关状态
  2. 关状态
  3. function getSwitchStatus(th) {
  4.     return $(th).hasC// 设置开关
  5. );
  6. }
  7.  
  8. // 设置开关
  9. function setSwitch2On(th) {
  10.     sliderOnOrOff('open', th);
  11. }
  12.  
  13. function setSwitch2Off(th) {
  14. // 开关切换
  15. f('close', th);
  16. }
  17.  
  18.  
  19. // å¼€// var ele = $(th).children(".move");
  20. ge(th) {
  21.     // var ele = $(th).children(".move");
  22.     var ele = $(th).children(".move");
  23.     var nextOpen = false;
  24.     if (ele.attr("data-state") == "switch_on") {
  25.         nextOpen = false;
  26.     } else {
  27.         nextOpen = true;
  28.     }
  29.     var bigType = false;
  30. // console.log('大类');
  31. oad-heading')) {
  32.         // console.log('å¤// console.log('小类');
  33. e = true;
  34.     } else {
  35.         // c//当前滑块滑动
  36. »');
  37.         bigType = false;
  38.     }
  39.     //当剨//开关小类
  40. »‘动
  41.     sliderOnOrOff('auto', th);
  42.     if (bigType) {
  43.         //开关小类
  44.         $(th).parents('dl').siblings('section').each(function () {
  45.             if (nextOpen) {
  46.                 if ($(this).find('.btn_fath .move').attr('data-state') === 'switch_off') {
  47.                     sliderOnOrOff('open', $(this).find('.btn_fath'));
  48.                 }
  49.             } else {
  50.                 if ($(this).find('.btn_fath .move').attr('data-state') === 'switch_on') {
  51.                     sliderOnOrOff('cl//判断是否开关大类
  52. th'));
  53.                 }
  54.             }
  55.  
  56.         });
  57.     } else {
  58.         //判断是否开关大类
  59.         var dlItem = $(th).parents('dl').parents('section').eq(0).siblings('dl'data-state'var bigTypeBtn = dlItem.find('.broad-heading');
  60.         var bigTypeCurrentType = bigTypeBtn.children('.move').attr('data-state');
  61.         var list = dlItem.parent().children('section').filter(function () {
  62.             return $(//关闭总开关
  63. ath_sub .move').attr('data-state') === 'switch_on';
  64.         });
  65.         if (list.length === 0) {
  66.             //关闭总开关
  67.             if (bigTypeCu//开启总开关
  68. tch_on') {
  69.                 sliderOnOrOff('close', bigTypeBtn);
  70.             }
  71.         } else if (list.length === 1) {
  72.             //开启总开关
  73.             if (bigTypeCurrentType === 'switch_off') {
  74.                 sliderOnOrOff('open', bigTypeBtn);
  75.             }
  76.         }
  77.     }
  78. }
  79.  
  80.  
  81. function sliderOnOrOff(type, th) {
  82.     var ele = $(th).children(".move");
  83.     var animateLen//开启
  84. ;
  85.     if ($(th).hasClass('push-all-type')) {
  86.         animateLen = '22px';
  87.     } else {
  88.         animateLen = '27px';
  89.     }
  90.     if (type === 'open') {
  91.         //开启
  92.         ele.attr("data-state", "switch_on");
  93.         ele.animate({
  94.                 left: animateLen
  95.             },
  96.             200,
  97.             function () {
  98.                 ele.parent(".btn_fath").addClass("switch_on//关闭
  99. Class("switch_off"data-state"        $(th).parents(".pushlist_m").children("p").text("已开启推送");
  100.             });
  101.     } else if (type === 'close') {
  102.         //关闭
  103.         ele.attr("data-state", "switch_off");
  104.         ele.animate({
  105.                 left: "1"
  106.             },
  107.             200,
  108.             function () {
  109.                 ele.parent(//自动判断
  110. dClass("switch_off").removeClass("switch_on");
  111.                 $(th).parents(".pushlist_m").children("p").text("不推送");
  112.             });
  113.     } else if (t

Raw Paste


Login or Register to edit or fork this paste. It's free.