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

本小妞迷上赌 提交于 2019-12-11 14:59:40

问题


I'm using the elastic grid plugin for a grid display system on a site, but I want to be able to simply click off the expanded view and it automatically close without having to click on the thumbnail or 'x' button as the plugin suggests.

I've had a bit of a look through the code and think this is where I need to edit

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;
    });

However, I'm not sure exactly how to do this. I was trying to implement this method mentioned here but am having no luck. Any guidance in this would be appreciated.

The plugin for reference: http://demo.phapsu.com/jquery.elastic_grid/


回答1:


if you haven't found an answer yet, add this your js page, it will close the expanded view if you click any where in the page except the expanded view it self.

$('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");  
});


来源:https://stackoverflow.com/questions/28145402/forking-elastic-grid-plugin-to-be-able-to-close-preview-by-clicking-anywhere-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!