mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 09:49:28 +02:00
Run ads only when container is visible
This commit is contained in:
parent
5b009798ec
commit
7d404210b1
1 changed files with 16 additions and 2 deletions
|
@ -2237,9 +2237,23 @@ function downloadURLOrAlertError(jsonURL, data, filename) {
|
|||
}
|
||||
|
||||
function startGoogleAd(selector, timeout){
|
||||
if($(selector).is(":visible") && $(selector).height() >= 80 && $(selector).width() >= 200){
|
||||
if(isVisibleAndInViewport(selector)){
|
||||
setTimeout(function(){(adsbygoogle = window.adsbygoogle || []).push({});},timeout);
|
||||
}else{
|
||||
setTimeout(function(){startGoogleAd(selector, timeout);},1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function isVisibleAndInViewport(selector){
|
||||
if($(selector).is(":visible")){
|
||||
var elementTop = $(selector).offset().top;
|
||||
var elementBottom = elementTop + $(selector).outerHeight();
|
||||
|
||||
var viewportTop = $(window).scrollTop();
|
||||
var viewportBottom = viewportTop + $(window).height();
|
||||
|
||||
return elementBottom > viewportTop && elementTop < viewportBottom;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue