JQuery UI Show -有人可以缩短函数,以便只使用“盲”吗?[已关闭]

t9aqgxwy  于 2023-08-04  发布在  jQuery
关注(0)|答案(1)|浏览(79)

已关闭。此问题需要更多focused。它目前不接受回答。
**希望改进此问题?**更新问题,使其仅针对editing this post的一个问题。

10天前关门了。
Improve this question
我用的是jQuery UI。
在显示功能的情况下,我只需要选择“盲”。
有人可以请缩短功能,使只有“盲目”使用?
所有选择选项都必须取消。脚本应该只包含“盲”选项。
var selectedEffect =有人可以缩短功能,以便只使用“盲”?

$(function() {
  // run the currently selected effect
  function runEffect() {
    // get effect type from
    var selectedEffect = $("#effectTypes").val();

    // Most effect types need no options passed by default
    var options = {};
    // some effects have required parameters
    if (selectedEffect === "scale") {
      options = {
        percent: 50
      };
    } else if (selectedEffect === "size") {
      options = {
        to: {
          width: 280,
          height: 185
        }
      };
    }

    // Run the effect
    $("#effect").show(selectedEffect, options, 500, callback);
  };

  //callback function to bring a hidden box back
  function callback() {
    setTimeout(function() {
      $("#effect:visible").removeAttr("style").fadeOut();
    }, 1000);
  };

  // Set effect from select menu value
  $("#button").on("click", function() {
    runEffect();
  });

  $("#effect").hide();
});

个字符

nwsw7zdq

nwsw7zdq1#

你可以硬编码

var selectedEffect = 'blind';

字符串
或删除所有其他选项

$("#effectTypes")[0].length = 1;

$(function() {
  $("#effectTypes")[0].length = 1;
  // run the currently selected effect
  function runEffect() {
    // get effect type from
    var selectedEffect = $("#effectTypes").val();

    // Most effect types need no options passed by default
    var options = {};
    // some effects have required parameters
    if (selectedEffect === "scale") {
      options = {
        percent: 50
      };
    } else if (selectedEffect === "size") {
      options = {
        to: {
          width: 280,
          height: 185
        }
      };
    }

    // Run the effect
    $("#effect").show(selectedEffect, options, 500, callback);
  };

  //callback function to bring a hidden box back
  function callback() {
    setTimeout(function() {
      $("#effect:visible").removeAttr("style").fadeOut();
    }, 1000);
  };

  // Set effect from select menu value
  $("#button").on("click", function() {
    runEffect();
  });

  $("#effect").hide();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.2/jquery-ui.min.js"></script>
<div class="toggler">
  <div id="effect" class="ui-widget-content ui-corner-all">
    <h3 class="ui-widget-header ui-corner-all">Show</h3>
    <p>
      Etiam libero neque, luctus a, eleifend nec, semper at, lorem. Sed pede. Nulla lorem metus, adipiscing ut, luctus sed, hendrerit vitae, mi.
    </p>
  </div>
</div>

<select name="effects" id="effectTypes">
  <option value="blind">Blind</option>
  <option value="bounce">Bounce</option>
  <option value="clip">Clip</option>
  <option value="drop">Drop</option>
  <option value="explode">Explode</option>
  <option value="fade">Fade</option>
  <option value="fold">Fold</option>
  <option value="highlight">Highlight</option>
  <option value="puff">Puff</option>
  <option value="pulsate">Pulsate</option>
  <option value="scale">Scale</option>
  <option value="shake">Shake</option>
  <option value="size">Size</option>
  <option value="slide">Slide</option>
</select>

<button id="button" class="ui-state-default ui-corner-all">Run 
    Effect</button>

的字符串

相关问题