0

我想在页面加载时启动一个 Fancybox。我可以将它绑定到隐藏的锚标记并通过 JavaScript 触发该锚标记的单击事件。bt 仅在某些条件为 true 时才打开它。我该怎么做?

4

2 回答 2

0
$(function() {
    if(condition) {
        $.fancybox({
            // fancybox options
        });
    }
});
于 2012-04-13T03:04:20.070 回答
0

Call it on the document ready. You can check your conditions and then invoke

var yourConditionVariableVal =false;
$(function(){
  if(yourConditionVariableVal)
  {
     $("#yourImage").fancybox();
  }
});

The above code will bind the fancy box to an element with id yourImage.

If you want to show the fancybox on page load event, you can trigger it.

var yourConditionVariableVal =false;
$(function(){
  if(yourConditionVariableVal)
  {
     $("#yourImage").fancybox();
     $("#yourImage").trigger("click");
  }
});
于 2012-04-13T03:03:27.653 回答