<tfoot id='9vhJr'></tfoot>
    1. <legend id='9vhJr'><style id='9vhJr'><dir id='9vhJr'><q id='9vhJr'></q></dir></style></legend>
      • <bdo id='9vhJr'></bdo><ul id='9vhJr'></ul>
    2. <i id='9vhJr'><tr id='9vhJr'><dt id='9vhJr'><q id='9vhJr'><span id='9vhJr'><b id='9vhJr'><form id='9vhJr'><ins id='9vhJr'></ins><ul id='9vhJr'></ul><sub id='9vhJr'></sub></form><legend id='9vhJr'></legend><bdo id='9vhJr'><pre id='9vhJr'><center id='9vhJr'></center></pre></bdo></b><th id='9vhJr'></th></span></q></dt></tr></i><div id='9vhJr'><tfoot id='9vhJr'></tfoot><dl id='9vhJr'><fieldset id='9vhJr'></fieldset></dl></div>

      <small id='9vhJr'></small><noframes id='9vhJr'>

      1. jQuery(event):监视元素样式

        时间:2023-09-04
          <bdo id='HQfeI'></bdo><ul id='HQfeI'></ul>
        • <small id='HQfeI'></small><noframes id='HQfeI'>

            • <i id='HQfeI'><tr id='HQfeI'><dt id='HQfeI'><q id='HQfeI'><span id='HQfeI'><b id='HQfeI'><form id='HQfeI'><ins id='HQfeI'></ins><ul id='HQfeI'></ul><sub id='HQfeI'></sub></form><legend id='HQfeI'></legend><bdo id='HQfeI'><pre id='HQfeI'><center id='HQfeI'></center></pre></bdo></b><th id='HQfeI'></th></span></q></dt></tr></i><div id='HQfeI'><tfoot id='HQfeI'></tfoot><dl id='HQfeI'><fieldset id='HQfeI'></fieldset></dl></div>

                  <tbody id='HQfeI'></tbody>
                <tfoot id='HQfeI'></tfoot>

              1. <legend id='HQfeI'><style id='HQfeI'><dir id='HQfeI'><q id='HQfeI'></q></dir></style></legend>
                1. 本文介绍了jQuery(event):监视元素样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  假设有这样的元素

                  <div class="watch-me" style="display: none;">Watch Me Please</div>
                  

                  我们可以看到上面的元素样式是display: none,我如何制作脚本来观看这个元素.当该元素样式更改为 display: block 时会触发一些代码.

                  as we can see the element above style is display: none, how can i make script to watch this element. when that element style is change to display: block then there is some code will be trigger.

                  非常感谢...

                  推荐答案

                  据我所知,唯一的方法就是使用计时器.

                  As far as I know, the only way to do this would be with a timer.

                  我创建了一个小型 jQuery 插件(是的,就在这里,现在),它针对 jQuery 集执行此操作:

                  I created a small jQuery plugin (yes, right here, right now) that does this against a jQuery set:

                  EDIT 这个插件现在在 GitHub 上:https://github.com/jacobrelkin/jquery-watcher

                  EDIT this plugin is now on GitHub: https://github.com/jacobrelkin/jquery-watcher

                  $.fn.watch = function(property, callback) {
                     return $(this).each(function() {
                         var self = this;
                         var old_property_val = this[property];
                         var timer;
                  
                         function watch() {
                            if($(self).data(property + '-watch-abort') == true) {
                               timer = clearInterval(timer);
                               $(self).data(property + '-watch-abort', null);
                               return;
                            }
                  
                            if(self[property] != old_property_val) {
                               old_property_val = self[property];
                               callback.call(self);
                            }
                         }
                         timer = setInterval(watch, 700);
                     });
                  };
                  
                  $.fn.unwatch = function(property) {
                     return $(this).each(function() {
                         $(this).data(property + '-watch-abort', true);
                     });
                  };
                  

                  用法:

                  $('.watch-me').watch('style', function() {
                     //"this" in this scope will reference the object on which the property changed
                     if($(this).css('display') == 'block') { 
                         //do something...
                     }
                  });
                  

                  要清除此属性观察器:

                  $('.watch-me').unwatch('style');
                  

                  这篇关于jQuery(event):监视元素样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何创建一个事件侦听器来检测布尔变量是否为 下一篇:Javascript 滚动处理程序未触发

                  相关文章

                  最新文章

                2. <tfoot id='4cXUe'></tfoot>
                  • <bdo id='4cXUe'></bdo><ul id='4cXUe'></ul>
                  <i id='4cXUe'><tr id='4cXUe'><dt id='4cXUe'><q id='4cXUe'><span id='4cXUe'><b id='4cXUe'><form id='4cXUe'><ins id='4cXUe'></ins><ul id='4cXUe'></ul><sub id='4cXUe'></sub></form><legend id='4cXUe'></legend><bdo id='4cXUe'><pre id='4cXUe'><center id='4cXUe'></center></pre></bdo></b><th id='4cXUe'></th></span></q></dt></tr></i><div id='4cXUe'><tfoot id='4cXUe'></tfoot><dl id='4cXUe'><fieldset id='4cXUe'></fieldset></dl></div>

                    1. <legend id='4cXUe'><style id='4cXUe'><dir id='4cXUe'><q id='4cXUe'></q></dir></style></legend>

                      <small id='4cXUe'></small><noframes id='4cXUe'>