2013-12-17 115 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 –