【问题标题】:Jquery grid overlay in wordpressWordPress中的jQuery网格覆盖
【发布时间】:2010-12-26 19:45:04
【问题描述】:

我正在添加这个在静态 html 站点中工作的简单插件,并尝试将其添加到基于 960 gs 的 wordpress 开发站点。 jquery 代码链接是正确的,但控制台给了我这个错误“Uncaught TypeError: Cannot call method 'addGrid' of null”我从这个教程http://www.badlydrawntoy.com/2009/04/21/960gs-grid-overlay-a-jquery-plugin/得到了代码

这是我正在使用的代码

/*<![CDATA[*/
    // onload
    $(function() {

        $("body").addGrid(12, {img_path: 'img/'});
    });
/*]]>*/

这是插件的代码

/*
 * @ description: Plugin to display 960.gs gridlines See http://960.gs/
 * @author: badlyDrawnToy sharp / http://www.badlydrawntoy.com
 * @license: Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
 * @version: 1.0 20th April 2009
*/
(function($){$.fn.addGrid=function(cols,options){var defaults={default_cols:12,z_index:999,img_path:'/images/',opacity:.6};var opts=$.extend(defaults,options);var cols=cols!=null&&(cols===12||cols===16)?cols:12;var cols=cols===opts.default_cols?'12_col':'16_col';return this.each(function(){var $el=$(this);var height=$el.height();var wrapper=$('<div id="'+opts.grid_id+'"/>').appendTo($el).css({'display':'none','position':'absolute','top':0,'z-index':(opts.z_index-1),'height':height,'opacity':opts.opacity,'width':'100%'});$('<div/>').addClass('container_12').css({'margin':'0 auto','width':'960px','height':height,'background-image':'url('+opts.img_path+cols+'.png)','background-repeat':'repeat-y'}).appendTo(wrapper);$('<div>grid on</div>').appendTo($el).css({'position':'absolute','top':0,'left':0,'z-index':opts.z_index,'background':'#222','color':'#fff','padding':'3px 6px','width':'40px','text-align':'center'}).hover(function(){$(this).css("cursor","pointer");},function(){$(this).css("cursor","default");}).toggle(function(){$(this).text("grid off");$('#'+opts.grid_id).slideDown();},function(){$(this).text("grid on");$('#'+opts.grid_id).slideUp();});});};})(jQuery);

【问题讨论】:

    标签: jquery wordpress grid overlay


    【解决方案1】:

    我很确定 WordPress 使用 Jquery.noConflict(),因此取决于您如何调用 jQuery,这可能是您的问题。试试

        /*<![CDATA[*/
        // onload
        jQuery(function() {
    
            $("body").addGrid(12, {img_path: 'img/'});
        });
    /*]]>*/
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-03
      • 1970-01-01
      • 1970-01-01
      • 2019-11-28
      • 1970-01-01
      • 1970-01-01
      • 2018-06-08
      相关资源
      最近更新 更多