2017-02-20 60 views
0

我試圖在使用jquery加載視頻時嘗試添加preloader。問題是,它在除Safari之外的每個瀏覽器都能正常工作。HTML5視頻中的加載程序不能在Safari中工作

JSFIDDLE

這是代碼。

$('#video_id').on('loadstart', function(event) { 
 
    $(this).addClass('loading'); 
 
}); 
 
$('#video_id').on('canplay', function(event) { 
 
    $(this).removeClass('loading'); 
 
    $(this).attr('poster', ''); 
 
});
video.loading { 
 
    background: black url(http://www.drivethrurpg.com/shared_images/ajax-loader.gif) center center no-repeat; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<video controls="" poster="http://www.drivethrurpg.com/shared_images/ajax-loader.gif"> 
 
    <source src="https://www.w3schools.com/html/movie.mp4" type="video/mp4"> 
 

 
</video>

回答

0

首先,video - 元素犯規有#video_id -id。其次,你正在使用加載器的海報,這意味着如果佔位符顯示在其上方,則不會看到背景圖像。我在Safari瀏覽器中看到加載海報。

我用視頻上的正確ID更新了代碼。

$('#video_id').on('loadstart', function(event) { 
 
    $(this).addClass('loading'); 
 
}); 
 
$('#video_id').on('canplay', function(event) { 
 
    $(this).removeClass('loading'); 
 
    $(this).attr('poster', ''); 
 
});
video.loading { 
 
    background: black url(http://www.drivethrurpg.com/shared_images/ajax-loader.gif) center center no-repeat; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<video id="video_id" controls="" poster="http://www.drivethrurpg.com/shared_images/ajax-loader.gif"> 
 
    <source src="https://www.w3schools.com/html/movie.mp4" type="video/mp4"> 
 

 
</video>

+0

感謝您的答覆和糾正我的錯誤,但仍然代碼沒有在Safari –

+0

工作什麼不工作?海報和背景圖片都適合我。我正在使用'Safari 10.0.3'。你在談論iOS或macOS上的Safari嗎? –

+0

IOS中的Safari 5.1.7。 –