简体   繁体   English

如果以毫秒为单位,将传递给jQuery slideToggle()的速度变量忽略

[英]Passed speed variable to jQuery slideToggle() is ignored if in milliseconds

I'm having a strange issue, and my google-fu is failing me. 我遇到了一个奇怪的问题,而我的Google-fu让我失败了。 I'm working on a WordPress plugin, and I'm passing variables from the settings page to the jQuery script. 我正在使用WordPress插件,并且正在将变量从设置页面传递到jQuery脚本。 It's all passing perfectly fine, except that within the script, it's completely ignoring the value for the speed in slideToggle(). 一切顺利,除了脚本内,它完全忽略了slideToggle()中的speed值。

For the record, I'm loading a jQuery script (jQuery UI - v1.11.2): core and effects. 作为记录,我正在加载一个jQuery脚本(jQuery UI-v1.11.2):核心和效果。

Here is my script: 这是我的脚本:

jQuery(document).ready(function($) {
  var $show_open_by_default = wp_settings.expanded;
  var $showtext = wp_settings.show;
  var $hidetext = wp_settings.hide;
  var $speed = wp_settings.toggle_down;
  var $easing = wp_settings.easing;

  if($show_open_by_default != 1) { // if setting is unchecked...
      $('.comment .children').hide(); // hide all children on load
  }

  $('.comment-list > li').each(function() {
    if( $(this).find('.children').length > 0 ) {
      $(this).find('.children').before('<div class="replylink"><span class="show">'+$showtext+'</span></div>');
    }
  });

  $('.replylink').hover(function() {       // when hovering the replylink...
    $(this).css('cursor','pointer');       // change the cursor...
  }, function() { 
    $(this).css('cursor','auto'); 
  }).click(function() {                     // and on click...
    // change the text
    $(this).text( $(this).text() == $hidetext ? $showtext : $hidetext); 

    // animate the visibility of the children
    var $nextDiv = $(this).next();
    var $visibleSiblings = $nextDiv.siblings('div:visible');

    if ($visibleSiblings.length == 0 ) {
        $visibleSiblings.slideToggle($speed, $easing);      
    } else { 
        $nextDiv.slideToggle($speed, $easing);
    }
  });
});

It all works perfectly fine, except for the slideToggle() call at the end. 除了最后的slideToggle()调用之外,其他所有功能都工作正常。 If I place alert($speed); 如果我发出警报($ speed); just before the slideToggle() call, it does, indeed, alert the correct setting just fine. 实际上,在调用slideToggle()之前,它确实可以警告正确的设置。 However, the slideToggle ignores it and reverts to the default speed. 但是,slideToggle会忽略它并恢复为默认速度。

What's funny is, if I manually put in a value, it works just fine. 有趣的是,如果我手动输入一个值,它就可以正常工作。 But with the passed value, it ignores it. 但是使用传递的值,它将忽略它。 I am completely stumped on this. 我对此完全感到困惑。 I've tried everything I can think of to make it pay attention to that number, but it will only do so if I hard-code it in the slideToggle() call. 我已经尽力想让它注意该数字,但是只有在slideToggle()调用中对其进行硬编码时,它才会这样做。 If it's passed, it won't pay attention to it. 如果通过了,它不会关注它。 Am I missing something? 我想念什么吗?

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks! 谢谢!

Just wanted to post the the solution was found - but the answer is in the comments. 只是想发布找到解决方案的方法-但答案在注释中。 Basically, the passed value is a string, not numeric. 基本上,传递的值是字符串,而不是数字。 So I have some conversion to do in my PHP file to be sure the value is passed correctly based on the type. 因此,我需要在PHP文件中进行一些转换,以确保根据类型正确传递值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM