Add jQuery colorbox plugin to a dynamically created element

前端 未结 6 1392
别跟我提以往
别跟我提以往 2020-12-15 07:36

The usual way to assign color box functionality on a link is like this:

$(\"a.colorbox\").colorbox({ transition: \"elastic\" });

Newly added

6条回答
  •  春和景丽
    2020-12-15 08:06

    This post is old but this may help others: simonthetwit solution is ok, but you'll need to click the trigger link twice. Colorbox can be called directly, so this should work:

    $( '.colorbox' ).live('click',function(e){
            e.preventDefault();
            $.colorbox({open:true});
            //inline example
            //$.colorbox({inline:true, width:"50%", href:"#inline_content"});
    });
    

    Cheers!

提交回复
热议问题