Forum

Guest  

Welcome Guest, posting in this forum requires registration.

Pages: [1] 2
Topic: Countdown
eddyemmer
Member
Posts: 39
Countdown
on: October 21, 2013, 11:14

Hoi,


Ik heb een countdown scriptje dat ik inmiddels heb kunnen draaien op mijn site. Alleen hij laat de countdown bij 1 feed zijn. De eerste.


Dit is mijn script:


<div class=\"".$storename."store-outerbox store-outerbox\">

<div id=\"timer\" class=\"".$storename."store-timer store-timer\">Dagelijks om 0:00

<script>

(function() {

var d=new Date();

var tomorrow = new Date(d.getTime() + 24 * 60 * 60 * 1000);

tomorrow.setHours(0);

tomorrow.setMinutes(0);

tomorrow.setSeconds(0);


var target_date = tomorrow;

// variables for time units

var days, hours, minutes, seconds;

// get tag element

var countdown = document.getElementById('timer');

// update the tag with id 'countdown' every 1 second

setInterval(function () {

// find the amount of 'seconds' between now and target

var current_date = new Date().getTime();

var seconds_left = (target_date – current_date) / 1000;

// do some time calculations

days = parseInt(seconds_left / 86400);

seconds_left = seconds_left % 86400;


hours = parseInt(seconds_left / 3600);

seconds_left = seconds_left % 3600;


minutes = parseInt(seconds_left / 60);

seconds = parseInt(seconds_left % 60);


// format countdown string + set tag value

countdown.innerHTML = 'Nog '+ hours + ' uur en ' + minutes + ' minuten' ;

}, 1000);

})();

</script></div>


<div class=\"".$storename."store-logo store-logo\">

<div class=\"".$storename."store-logo-image store-logo-image\"></div>


</div>

<div class=\"".$storename."store-image store-image\">

<a href=\"".$image."\" ".$rel." ".$imagerel." ".$target.">

<img src=\"".$imageURL."\" alt=\"".$productname."\" title=\"".$productname."\"/>

</a>

</div>


<div class=\"".$storename."store-titel store-titel\">

".$productname."

</div>

<div class=\"".$storenam."store-price-div store-price-div\">

<div class=\"".$storename."store-price store-price\">

<a href=\"".$producturl."\" ".$rel." class=\"regular\" ".$urltarget." title=\"".$productname."\">

".$price."

</a>

</div>

</div>

<div class=\"".$storename."store-footer store-footer\">


".$more."


<div class=\"".$storename."buttons buttons\">

<a href=\"".$producturl."\" ".$rel." class=\"regular\" ".$urltarget." title=\"".$productname."\">

".$buynow."


</a>

</div>

</div>

</div>";


Hoe kan ik er voor zorgen dat hij bij alle feeds deze countdown laat zien. Als je kijkt op www. kiesaanbieding. nl dan zie je dat hij alleen bij de eerst de countdown heeft.


Thanks


RPG
Administrator
Posts: 326
Re: Countdown
on: October 21, 2013, 11:45

Je mag maar 1 id op je pagina hebben.


Dus getelementid zal alleen de eerste id pakken


Je kan beter met document.getElementsByClassName() werken


eddyemmer
Member
Posts: 39
Re: Countdown
on: October 21, 2013, 11:57

En dan getelementbyclassname ('$storename') ofzo iets?


RPG
Administrator
Posts: 326
Re: Countdown
on: October 21, 2013, 12:00

Denk dat het makkelijker is om je je huidige css id genaamd timer naar een class te veranderen en die te gebruiken.


eddyemmer
Member
Posts: 39
Re: Countdown
on: October 21, 2013, 12:05

Als ik dat doe dan werkt mijn script niet meer.


<div class=\"timer\" class=\"".$storename."store-timer store-timer\">Dagelijks om 0:00

<script>

(function() {

var d=new Date();

var tomorrow = new Date(d.getTime() + 24 * 60 * 60 * 1000);

tomorrow.setHours(0);

tomorrow.setMinutes(0);

tomorrow.setSeconds(0);


var target_date = tomorrow;

// variables for time units

var days, hours, minutes, seconds;

// get tag element

var countdown = document.getElementsByClassName('timer');

// update the tag with id 'countdown' every 1 second

setInterval(function () {

// find the amount of 'seconds' between now and target

var current_date = new Date().getTime();

var seconds_left = (target_date – current_date) / 1000;

// do some time calculations

days = parseInt(seconds_left / 86400);

seconds_left = seconds_left % 86400;


hours = parseInt(seconds_left / 3600);

seconds_left = seconds_left % 3600;


minutes = parseInt(seconds_left / 60);

seconds = parseInt(seconds_left % 60);


// format countdown string + set tag value

countdown.innerHTML = 'Nog '+ hours + ' uur en ' + minutes + ' minuten' ;

}, 1000);

})();

</script></div>


RPG
Administrator
Posts: 326
Re: Countdown
on: October 21, 2013, 12:12
<div class=\"timer\" class=\"".$storename."store-timer store-timer\">Dagelijks om 0:00

Ik zie daar nu 2 classes in de zelde div. je zou timer achter store-timer kunnen toevoegen.


eddyemmer
Member
Posts: 39
Re: Countdown
on: October 21, 2013, 12:20

Heb nu dit:


<div class=\"".$storename."store-timer store-timer\" class=\"timer\"\><script>

(function() {

var d=new Date();

var tomorrow = new Date(d.getTime() + 24 * 60 * 60 * 1000);

tomorrow.setHours(0);

tomorrow.setMinutes(0);

tomorrow.setSeconds(0);


var target_date = tomorrow;

// variables for time units

var days, hours, minutes, seconds;

// get tag element

var countdown = document.getElementsByClassName('timer');

// update the tag with id 'countdown' every 1 second

setInterval(function () {

// find the amount of 'seconds' between now and target

var current_date = new Date().getTime();

var seconds_left = (target_date – current_date) / 1000;

// do some time calculations

days = parseInt(seconds_left / 86400);

seconds_left = seconds_left % 86400;


hours = parseInt(seconds_left / 3600);

seconds_left = seconds_left % 3600;


minutes = parseInt(seconds_left / 60);

seconds = parseInt(seconds_left % 60);


// format countdown string + set tag value

countdown.innerHTML = 'Nog '+ hours + ' uur en ' + minutes + ' minuten' ;

}, 1000);

})();

</script></div>


En ook daar wil ie niet intrappen…..:-(


RPG
Administrator
Posts: 326
Re: Countdown
on: October 21, 2013, 12:23

Maar nu heb je nog steeds 2 classes in de div staan. Je hebt nu alleen de class achter de andere class gezet inplaats van ervoor. Je zult de 2 classes moeten combineren door timer achter store-timer te zetten.


eddyemmer
Member
Posts: 39
Re: Countdown
on: October 21, 2013, 12:26

<div class=\"".$storename."store-timer store-timer\"> <div class=\"timer\">

<script>

(function() {

var d=new Date();

var tomorrow = new Date(d.getTime() + 24 * 60 * 60 * 1000);

tomorrow.setHours(0);

tomorrow.setMinutes(0);

tomorrow.setSeconds(0);


var target_date = tomorrow;

// variables for time units

var days, hours, minutes, seconds;

// get tag element

var countdown = document.getElementsByClassName('timer');

// update the tag with id 'countdown' every 1 second

setInterval(function () {

// find the amount of 'seconds' between now and target

var current_date = new Date().getTime();

var seconds_left = (target_date – current_date) / 1000;

// do some time calculations

days = parseInt(seconds_left / 86400);

seconds_left = seconds_left % 86400;


hours = parseInt(seconds_left / 3600);

seconds_left = seconds_left % 3600;


minutes = parseInt(seconds_left / 60);

seconds = parseInt(seconds_left % 60);


// format countdown string + set tag value

countdown.innerHTML = 'Nog '+ hours + ' uur en ' + minutes + ' minuten' ;

}, 1000);

})();

</script>

</div>

</div>


Ook dit werkt niet..


RPG
Administrator
Posts: 326
Re: Countdown
on: October 21, 2013, 13:25

Mogelijk komt er een array uit de getelementsbyclassname. Dan zal je die allemaal af moeten gaan.


Ben je van plan om de javascript code bij elk object te zetten? Anders zou je in php kunnen maken dat elke:


<div id=timer> een nummer krijgt <div id=timer1> ….. <div id=timer2> en dat nummer ook in je javascript gebruiken. Ik weet alleen niet of het wel handig is om dan zoveel javascript in je pagina op te nemen


Pages: [1] 2
WP Forum Server by ForumPress | LucidCrew
Version: 4 ; Page loaded in: 0.013 seconds.