2011-02-10 11 views
0

我在colorbox modalpopup的頂部創建一個插件。使用colorbox和jquery插件分組圖像

jQuery插件

$(document).ready(function(){ 

(function($) { 

    $.fn.pop= function(options) { 

    var options = $.extend({}, $.fn.pop.defaults, options); 

    return this.each(function() { 
     var o = options; 
     var obj = $(this); 
     obj.click(function() { 
    obj.colorbox({height:o.h, width:o.w , iframe:true});  
    });  
    }); 
    };  
    $.fn.pop.defaults = { 
    h: '60%', 
w: '60%' 
    }; 
})(jQuery); 
}); 

在用戶層面,我只是讓他們打電話給 $ POP()( 「類名」)。 //如果他們需要優化長度寬度,他們只是給予編號

現在我的問題是,如果我需要組圖像,我必須做這樣的事情。

$("a[rel='example1']").colorbox(); 

insted的這個我需要調用我的函數

$("a[rel='example1']").pop(); 

但它沒有羣體本身。 anyhelp可以理解

回答

0

顏色框有一個「相對」的標籤屬性:我不知道到底把我的頭頂部,但應該是這樣的:

$(document).ready(function(){ 

(function($) { 

    $.fn.pop= function(options) { 

    var options = $.extend({}, $.fn.pop.defaults, options); 

    return this.each(function() { 
     var o = options; 
     var obj = $(this); 
     obj.click(function() { 
     // the following addition where o.r is options.rel = this.attr('rel'); 
     // or something like that 
     obj.colorbox({height:o.h, width:o.w , iframe:true, rel:o.r}); 
     });  
    }); 
    };  
    $.fn.pop.defaults = { 
    h: '60%', 
    w: '60%', 
    r: 'group1' 
    }; 
})(jQuery); 
}); 

還要記住,如果你在一阿賈克斯有你的插件的鏈接不會自己挑選它,因爲它利用了colorbox並對其進行了擴展,但你並沒有改變它使用'live'而不是'delegate'的事實。你可能想給這一個小小的研究...

和顏色框,對關係和分組偉大文檔: jacklmoore.com/colorbox/

請向下滾動到設置...閱讀文檔絕不是浪費時間,因爲無法找到論壇上的所有解決方案。