2013-12-17 116 views
0

我试着查看这个特定的场景,但找不到答案,我看到的答案没有多大帮助,所以我非常感谢这方面的帮助。这里在ajax调用后自动打开shadowbox

  • 项目列表,

    你点击一个项目,

    项目的照片被用ajax加载,

    自动开启太极拳(问题: 我想实现太极拳这样 - 它正在工作,除了在safari上)

此页面上的代码:

$(document).ready(function(){ 
    Shadowbox.init(); 
}) 

这是触发Ajax请求(问题是在太极拳开放部分在这里)代码:

$(document.body).on('click', '#pano_container .projectAjax', function(e) { 
    e.preventDefault(); 
    var id = $(this).attr("data-id"); 
    $.ajax({ 
     url: "actions/projectInfo.php", 
     type: 'GET', 
     dataType: 'html', 
     data: 'id='+id, 
     success: function(response, textStatus, XMLHttpRequest) { 
      if (!response){ 
       alert("There was an error!"); 
       return false; 
      } 
      else { 
       $("#imagestempcontainer").html(response); 

       Shadowbox.clearCache(); 
       //Shadowbox.setup(); 

       // before used to show the project photos, then user clicks...now it should autoamtically click, this worked everywhere except safari 
       //$("#imagestempcontainer a:first-child img").delay(50).click(); 

       // trying to fix this so it also works on safari, the below seems not working and gives 'undefined' in the console 
       Shadowbox.setup("#imagestempcontainer a"); 
       Shadowbox.open(this); 

      } 
     }, 
     error: function(XMLHttpRequest, textStatus, errorThrown) { 
      alert("There was an error!"); 
      if (typeof console != 'undefined') 
       console.dir(XMLHttpRequest); 
      return false; 
     } 
    }); 


}); 

这是收到的PHP/HTML代码通过Ajax请求:

foreach($projectPhotos as $k=>$projectPhoto){ 
    echo "<a style='display:none' href='".thumbnailLink($projectPhoto['image'],700,700)."' rel='shadowbox[{$project['title']}];player=img'>"; 
    echo "<img src='".thumbnailLink($projectPhoto['image'],650,350)."' />"; 
    echo "</a>"; 
} 
+0

那么究竟是什么问题呢? – MElliott

+0

一旦开放代码执行,它给未知玩家undefined,你可以在ma-t.net上检查它 –

+0

如果你只是从你的链接中删除'; player = img',会发生什么?或者你可以在.open中定义'player',如下所示:'Shadowbox.open({content:this,player:“img”});'不完全确定这是否是问题,但值得一试。 – MElliott

回答

0

好吧,我认为这可能是你的问题:

在你的Ajax CAL L提单Shadowbox.open(this);到:

$('#imagestempcontainer a').on('click',function(e){ 
    Shadowbox.open(this); 
    e.preventDefault(); 
}); 

您也可以尝试删除从你的链接;player=img,而是在Shadowbox.setup()这样定义它:

Shadowbox.setup("#imagestempcontainer a", {player: "img"}); 
+0

我该怎么做这在打开后自动打开阿贾克斯负载? 你点击项目,通过ajax收到照片列表,我希望直接打开为shadowbox –