Actually i am not that great with JS but i try to learn and i tried solving my own issue for 2 days but i couldn’t fix it so i am here to ask for help. my problem is i am trying to pause and resume count down timer with setinterval(); and when i use clearinterval(); it reset it when i recall setinterval(); again. here is my code:
[CODE]<script type=’text/javascript’>
document.getElementById(‘myVideo’).addEventListener(‘playing’,myHandler,false);
function myHandler(e) {
if(!e) { e = window.event; }
$(“#box”).hide();
var replay = document.getElementById(“replay”);
var container = document.getElementById(‘dl’);
var seconds = 10;
var timer;
var isPaused = false;
function countdown() {
seconds–;
if(seconds > 0 && !myVideo.paused) {
isPaused = false;
if(!isPaused) {
container.innerHTML = ‘<font color=”black”> You can Skip the Ad after <b>’+seconds+'</b> seconds.. </font>’;
}
} else if (seconds > 0 && myVideo.paused)
{
isPaused = true;
clearInterval(timer);
}else {
$(“#dl”).hide();
$(“#MyButton”).css({
‘cursor’:’pointer’,
‘display’:’block’})
$(“#replay”).css({
‘cursor’:’pointer’,
‘display’:’block’,
‘background-color’:’#ffffff’,
‘color’:’#3399ff’,
‘border’:’2px solid #ffffff’,
‘border-radius’ : ’25px’
})
clearInterval(timer);
}
}
timer = window.setInterval(countdown, 1000);
}
</script>
it works when i pause it but when i play vid again the timer count down from the start (10) and when i remove the clearinterval(); that inside
[CODE]else if (seconds > 0 && myVideo.paused)
{
isPaused = true;
clearInterval(timer);
}
this conditional, it actually kinda work by continue previous count down but bring with it new count down so it like go back and forth between paused second and new one.
what i need to accomplish from this code briefly:
1- when video first time plays which is when the page loads for first time the count down timer begins from (0secs)
2- if user paused the video the count down pause as well with the video.
3- when user play again the video after the pause the count down timer continue counting from second the user did paused at and not from begining.
4- restart back by counting down new 10 seconds when clicking replay button (this replay button don’t show up except when 10 seconds end tho).
point 1,2 and 4 already work in the code i provided above but my all problem is number 3 which is when i play the video again after a pause the count down begins counting from 10 if i include a clearInterval(); in condition of video.paused(); or if i didnt include clearInterval(); it will continue counting down from second i paused from but begining new one from 10 and timer keeps swinging between continued second and new one… if i only can stop new timer from begining it will be great and thats all i want and missing for me.
thats all and hopefully i get help from someone soon
Yours,
Maxwel
[CODE]<div id="time"></div>
<script>
target = document.getElementById("time");
endTime = new Date().getTime() + 30000; // 30 sec's in ms
function update(){
t=new Date().getTime(); // time reference NOW!
s = Math.floor( (endTime - t) / 1000); // how much time left
if( t > endTime ) clearInterval(x);
else target.innerHTML = s + " Sec.";
}
x = setInterval("update()",1000);
</script>[/CODE]
~. so your answer to overhead and memory issues is to throw more code at it? Especially the slow and overhead-wasting time function and complex math? AND the ridiculous bloated overhead of the fat bloated idiotic "framework" while at it?!?
That makes sense.
... also doesn't address starting and stopping based on the video's status, which is the OP's question... which using your method the handler for starting/stopping would have to recreate endTime in addition to calling setInterval again.
Well, unless one were to just allow setInterval to run and not do anything while the video is paused... As much of a "waste" of processing time as it might be, it might be the smoother way of handling it.[/QUOTE]
function countdown() {
if (myVideo.paused) return;
if (!myVideo.ended) {
if (seconds--) {
container.innerHTML = 'You can skip the ad after ' + seconds + ' seconds.';
return;
}
container.innerHTML = 'Put your skip link here';
}
clearInterval(timer);
}
I am making a big assumption here that what the OP really wants is a bypass of some sort for people who have either subscribed or paid for immediate access.[/quote]
As for the scathing comment from yourself, what are you proposing? all you have done so far is criticize the OP and my offering of a possible resolution to the problem.[/QUOTE]
[CODE]var replay = document.getElementById("replay");
var container = document.getElementById('dl');
var seconds = 10;
var timer;
var isPaused = false;
function countdown() {
if (myVideo.paused){ return;
}
if (!myVideo.ended) {
if (seconds--) {
container.innerHTML = '<font color="black"> You can Skip the Ad after <b>'+seconds+'</b> seconds.. </font>';
return;
}
$("#dl").hide();
$("#MyButton").css({
'cursor':'pointer',
'display':'block'})
$("#replay").css({
'cursor':'pointer',
'display':'block',
'background-color':'#ffffff',
'color':'#3399ff',
'border':'2px solid #ffffff',
'border-radius' : '25px'
})
}
clearInterval(timer);
}
timer = window.setInterval(countdown, 1000);
}
[/CODE]
var
replay = document.getElementById("replay"),
container = document.getElementById('dl'),
seconds = 10,
timer;
<i> </i> function countdown() {
<i> </i> if (myVideo.paused) return;
<i> </i> if ((!myVideo.ended) && (seconds--)) {
<i> </i> container.innerHTML = 'You can Skip the Ad after <span>'+seconds+'</span> seconds...';
<i> </i> return;
<i> </i> }
<i> </i> $("#dl").hide();
<i> </i> $("#MyButton").css({
<i> </i> 'cursor':'pointer',
<i> </i> 'display':'block'
<i> </i> });
<i> </i> $("#replay").css({
<i> </i> 'cursor':'pointer',
<i> </i> 'display':'block',
<i> </i> 'background-color':'#ffffff',
<i> </i> 'color':'#3399ff',
<i> </i> 'border':'2px solid #ffffff',
<i> </i> 'border-radius' : '25px'
<i> </i> });
<i> </i> clearInterval(timer);
<i> </i> }
<i> </i>}
<i> </i>timer = window.setInterval(countdown, 1000);
}
[CODE]<script type='text/javascript'>
document.getElementById('myVideo').addEventListener('playing',myHandler,false);
function myHandler(e) {
if(!e) { e = window.event; }
$("#box").hide();
$("#pause").show();
$("#clickhere").hide();
var
replay = document.getElementById("replay"),
container = document.getElementById('dl'),
seconds = 10,
timer;
function countdown() {
if (myVideo.paused) return;
if ((!myVideo.ended) && (seconds--)) {
container.innerHTML = 'You can Skip the Ad after <span>'+seconds+'</span> seconds...';
return;
}
$("#dl").hide();
$("#MyButton").css({
'cursor':'pointer',
'display':'block'
});
$("#replay").css({
'cursor':'pointer',
'display':'block',
'background-color':'#ffffff',
'color':'#3399ff',
'border':'2px solid #ffffff',
'border-radius' : '25px'
});
clearInterval(timer);
}
timer = window.setInterval(countdown, 1000);
}
</script>[/CODE]
[CODE]<script type='text/javascript'>
function play() {
if (myVideo.paused){
myVideo.play();
$("#play").hide();
$("#pause").show();
}}
function pause() {
if (!myVideo.paused){
myVideo.pause();
$("#pause").hide();
$("#play").show();
}}
</script>[/CODE]
<script type="text/javascript"><!--
(function(d) {
<i> </i>var
<i> </i> replay = d.getElementById('replay'),
<i> </i> container = d.getElementById('dl'),
<i> </i> myVideo = d.getElementById('myVideo'),
<i> </i> seconds = 10,
<i> </i> timer = false;
<i> </i>function eventAdd(e, event, handler) {
<i> </i> if (e.addEventListener) e.addEventListener(event, handler, false);
<i> </i> else e.attachEvent('on' + event, handler);
<i> </i>}
<i> </i>function countdown() {
<i> </i> if (myVideo.paused) return;
<i> </i> if ((!myVideo.ended) && (seconds--)) {
<i> </i> container.innerHTML = 'You can Skip the Ad after <span>'+seconds+'</span> seconds...';
<i> </i> return;
<i> </i> }
<i> </i> $("#dl").hide();
<i> </i> $("#MyButton").css({
<i> </i> 'cursor':'pointer',
<i> </i> 'display':'block'
<i> </i> });
<i> </i> $("#replay").css({
<i> </i> 'cursor':'pointer',
<i> </i> 'display':'block',
<i> </i> 'background-color':'#ffffff',
<i> </i> 'color':'#3399ff',
<i> </i> 'border':'2px solid #ffffff',
<i> </i> 'border-radius' : '25px'
<i> </i> });
<i> </i> clearInterval(timer);
<i> </i> timer = false;
<i> </i>}
<i> </i>eventAdd(myVideo, 'playing', function(e) {
<i> </i> $("#box").hide();
<i> </i> $("#pause").show();
<i> </i> $("#clickhere").hide();
<i> </i> if (timer !== false) timer = window.setInterval(countdown, 1000);
<i> </i>});
})(document);
--></script>
[CODE]<script type="text/javascript">
(function(d) {
var
replay = d.getElementById('replay'),
container = d.getElementById('dl'),
myVideo = d.getElementById('myVideo'),
seconds = 10,
timer = false;
function eventAdd(e, event, handler) {
if (e.addEventListener) e.addEventListener(event, handler, false);
else e.attachEvent('on' + event, handler);
}
function countdown() {
if (myVideo.paused) return;
if ((!myVideo.ended) && (seconds--)) {
container.innerHTML = 'You can Skip the Ad after <span>'+seconds+'</span> seconds...';
return;
}
$("#dl").hide();
$("#MyButton").css({
'cursor':'pointer',
'display':'block'
});
$("#replay").css({
'cursor':'pointer',
'display':'block',
'background-color':'#ffffff',
'color':'#3399ff',
'border':'2px solid #ffffff',
'border-radius' : '25px'
});
clearInterval(timer);
timer = false;
}
eventAdd(myVideo, 'playing', function(e) {
$("#box").hide();
$("#pause").show();
$("#clickhere").hide();
if (timer !== false) timer = window.setInterval(countdown, 1000);
});
})(document);
</script>[/CODE]
i have some questions if u don't u told me to stop using jquery so what i can use instead?[/quote]
also aint those <!-- --> are html commenting tags why u used them in above post?[/quote]
how we can check for "seconds--" if we are not decrementing the seconds before we check for it?[/quote]
if (seconds--) {
// do something
}
if (seconds) {
seconds--;
// do something
} else seconds--;
function eventAdd(e, event, handler), e.attachEvent('on' + event, handler);[/quote]
function(d)" and why u used "d" in "function(d)" ?[/quote]
(function(a) {
alert(a);
})('test');
for (t = 0; t < labels.length; t++) {
eventAdd(labels[t], 'click', function(e) { alert(e); });
}
<i>
</i>function clickLabel(e) { alert(e); }
for (t = 0; t < labels.length; t++) {
eventAdd(labels[t], 'click', clickLabel });
}
function(d) {
})(document);
also what are the strings that added in brackets that after any function? what are they useful for? cuz sometimes they are declared before the function and sometimes they are never declared and still i can see the pc get it.
[/quote]
secondly, i actually refresh the page in the 2nd/3rd visit after i set their count number to 0 to make sure they dont directed to the link before they watch the ads vid. i know it dont make much sense but i am not sure why i did it that way much. i feel dumb :S[/quote]
1- what is the difference between UTF-8 by the HTML 5 way, and ISO-8859-1 via the META way?[/quote]
2- what i can do instead of checking browser type then display code that suits it tho?[/quote]
3- do u want me to use css instead of attributes like CENTER, FONT, BGCOLOR, etc?[/quote]
4- I never knew mysql_ functions that i use are outdated/outmoded, so where i can find new funcs?[/quote]
mysql_connect("", "", "") or die(mysql_error());
mysql_select_db("") or die(mysql_error());
$result = mysql_query("SELECT * FROM name WHERE ip = '$client_ip'")
or die(mysql_error());
$row = mysql_fetch_array($result);
$db = new PDO(
'mysql:host=localhost;dbname=database',
'username',
'password'
);
$statement = $db->prepare('
SELECT *
FROM name
WHERE ip = :ip
');
$statement->execute([':ip' => $client_ip]);
if ($row = $statement->fetch('PDO::FETCH_ASSOC')) {
i was wondering if it is possible to detect each computer behind same ip? like how i can differentiate between a pc and another behind same ip? is there a way to get port number or some local ip to achieve that task?[/QUOTE]
if (
isset($_SESSION['test']) &&
($_SESSION['test'] == 1)
) {
0.1.9 — BETA 6.13