mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 19:42:38 +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){
|
function startGoogleAd(selector, timeout){
|
||||||
if($(selector).is(":visible") && $(selector).height() >= 80 && $(selector).width() >= 200){
|
if(isVisibleAndInViewport(selector)){
|
||||||
setTimeout(function(){(adsbygoogle = window.adsbygoogle || []).push({});},timeout);
|
setTimeout(function(){(adsbygoogle = window.adsbygoogle || []).push({});},timeout);
|
||||||
}else{
|
}else{
|
||||||
setTimeout(function(){startGoogleAd(selector, timeout);},1000);
|
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