分叉弹性网格插件,能够通过单击屏幕上的任意位置来关闭预览

Forking elastic grid plugin to be able to close preview by clicking anywhere on the screen

本文关键字:位置 任意 屏幕 单击 插件 网格 分叉      更新时间:2023-09-26

我正在将弹性网格插件用于网站上的网格显示系统,但我希望能够简单地单击展开的视图,它会自动关闭,而无需单击缩略图或插件建议的"x"按钮。

我已经浏览了一下代码,并认为这是我需要编辑的地方

function initEvents() {
    //when clicking an item, show the preview with the items info and larg image;
    //close the item if already expanded.
    //also close if clicking on the item's cross
    $items.on( 'click', function(e) {
        hidePreview();
        return false;
    } ).children( 'a' ).on( 'click', function(e) {
        
        var $item = $( this ).parent();
        //check if item already opened
        current === $item.index() ? hidePreview() : showPreview( $item );
        return false;
    });

但是,我不确定如何做到这一点。我试图实现这里提到的这种方法,但没有运气。如能提供这方面的任何指导,将不胜感激。

供参考的插件:http://demo.phapsu.com/jquery.elastic_grid/

如果您

还没有找到答案,请将其添加到您的 js 页面,如果您单击页面中除展开视图之外的任何位置,它将关闭展开的视图。

$('body').click(function(evt){    
       if(evt.target.class== "og-expander")
          return;
       // For descendants of menu_content being clicked, remove this
       // check if you do not want to put constraint on descendants.
       if($(evt.target).closest('.og-expander').length)
          return;             
        $(".og-close").trigger("click");  
});