Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Olá! Estou com um pequeno problema, é o seguinte, quando tento colocar uma data abaixo do dia 20 na seguinte função abaixo (Parte em NEGRITO) ela não funciona.
O back-end anterior fez da seguinte forma:
(Dexei um arquivo com o código todo em anexo.)
function getTimeRemaining(endtime){
var t = Date.parse(endtime) - Date.parse(new Date());
return {
'total': t,
'days': Math.floor( t / (1000 * 60 * 60 * 24) ),
'hours': Math.floor( (t / (1000 * 60 * 60) ) % 24 ),
'minutes': Math.floor( (t / 1000 / 60) % 60 )
};
}
// City Selector
$(function () {
var events_informations = {
'belo-horizonte': {
'title': 'Belo Horizonte',
'date': '08/07/2017',
'place': 'Dayrell Hotel - a partir das 8:00',
'imagePath': 'img/cities/bh/belo-horizonte-2.jpg',
'btnBuyNow': 'https://www.sympla.com.br/',
'btnDestinePage': '/belo-horizonte',
'mapPlace': {lat: -19.9226186, lng: -43.9401089},
'datetime': 'June 20 2017 8:30:00 GMT-03:00'
}
};
function getNextDestines(events_informations) {
var nextDestines = [];
var keys = Object.keys(events_informations);
for (var i = 0; i < keys.length; i++) {
var today = new Date();
var date = new Date(events_informations[keys]['datetime']);
if (date.getTime() > today.getTime() && date.getDate() > today.getDate()) {
nextDestines = [events_informations[keys], events_informations[keys[i+1]], events_informations[keys[i+2]], events_informations[keys[i+3]]];
break;
}
}
return nextDestines;
};
*Será que vocês podem me ajudar nessa?*
Muito obrigado!
Obrigado pela ajuda Willian, mas infelizmente ainda continua dando o erro.
Quando troco a data do dia para alguma data abaixo do dia 20 some. Eu queria colocar dia 8. você sabe oque pode ser?
Ficou da seguinte forma:
// City Selector
$(function () {
var events_informations = {
'belo-horizonte': {
'title': 'Belo Horizonte',
'date': '08/07/2017',
'place': 'Dayrell Hotel - a partir das 8:00',
'imagePath': 'img/cities/bh/belo-horizonte-2.jpg',
'btnBuyNow': 'https://www.sympla.com.br/',
'btnDestinePage': '/belo-horizonte',
'mapPlace': {lat: -19.9226186, lng: -43.9401089},
'datetime': new Date(2017,7,8,8,30).toISOString()
}Não.. meio difícil dizer.. pode ser que não tenha dados para trazer.
aparece algo no console de erros? Ctrl + Shift +J no Firefox ou Chrome?
Tentei olhar aqui, mas não apareceu nenhum erro no painel.
Não sei pq não aceita número menor que 20, ta me pirando isso kk
Não sei mais oque fazer.
Tenta ver se os formatos dessas datas estão batendo:
var today = new Date();
var date = new Date(events_informations[keys]['datetime']);
vai saber né rsrs...
Tenta tirar o break e colocar um else também:
if (date.getTime() > today.getTime() && date.getDate() > today.getDate()) {
nextDestines = [events_informations[keys], events_informations[keys[i+1]], events_informations[keys[i+2]], events_informations[keys[i+3]]];
break;
}
Boa sorte!!Olá Douglas, infelizmente não deu certo, vocês acham que eu deveria tentar fazer de outra forma? Teria maneira mais simples de fazer esse contador de tempo?
Vê se este exemplo ajuda.
Infelizmente ainda não deu, vou postar o código todo pra vocês dar uma olhada.
Me parece que eu entendi um pouco oque o web anterior fez, me parece que tinha mais unidades, outras cidades e ele ia mudando de acordo com o tempo. Agr já não aceita abaixo do dia 25, será como posso resolver este problema?
Segue o Código:
var map;
var marker;
(function($){
$(document).ready(function (){
// Scrool button
$('a.see-btn').click(function(){
var topCount = ( $ ( $.attr(this, 'href') ).offset().top ) +1;
$('html, body').animate({ scrollTop: topCount }, 1000);
return false;
});
$('a.scroll-btn').click(function(){
var topCount = ( $ ( $.attr(this, 'href') ).offset().top ) -150;
$('html, body').animate({ scrollTop: topCount }, 1000);
return false;
});
//Tooltips
$(function () {
$('[data-toggle="tooltip"]').tooltip()
});
// City Selector
$(function () {
var events_informations = {
'belo-horizonte': {
'title': 'Belo Horizonte',
'date': '21/06/2017',
'place': 'Dayrell Hotel - a partir das 8:30',
'imagePath': 'img/cities/bh/belo-horizonte-2.jpg',
'btnBuyNow': 'https://www.sympla.com.br/',
'btnDestinePage': '/belo-horizonte',
'mapPlace': {lat: -19.9226186, lng: -43.9401089},
'datetime': 'july 25 2017 00:00 GMT-03:00'
}
};
$('.btn-city').on('click', function() {
var city = $(this).attr('data-id');
$('#event-city').html(events_informations[city]['title']);
$('#event-date').html(events_informations[city]['date']);
$('#event-place').html(events_informations[city]['place']);
$('.destinations').css('background-image', 'url("'+events_informations[city]['imagePath']+'")');
$('#btnBuyNow').attr('href', events_informations[city]['btnBuyNow']);
$('#btnDestinePage').attr('href', events_informations[city]['btnDestinePage']);
map.setCenter(events_informations[city]['mapPlace']);
marker.setPosition(events_informations[city]['mapPlace']);
if ( events_informations[city]['mapZoom'] ){
map.setZoom(events_informations[city]['mapZoom']);
marker.setPosition({lat: -1, lng: -1});
}
else{
map.setZoom(15);
};
});
var nextDestines = getNextDestines(events_informations);
initializeClock(nextDestines);
var timeinterval = setInterval(function(){
initializeClock(nextDestines);
},30000);
});
// Scrool Navbar
$(window).scroll(function(){
var vh = $('#hero + *').offset().top;
var scroll_top = $(window).scrollTop();
var jqObject = $('.navbar')
if(scroll_top > vh){
jqObject.removeClass('top-position');
} else{
$('.navbar-default').addClass('top-position');
}
});
});
})(jQuery);
function getTimeRemaining(endtime) {
var t = Date.parse(endtime) - Date.parse(new Date());
return {
'total': t,
'days': Math.floor(t / (1000 * 60 * 60 * 24)),
'hours': Math.floor((t / (1000 * 60 * 60)) % 24),
'minutes': Math.floor((t / 1000 / 60) % 60)
};
}
function initializeClock(next) {
for (let i = 0 ; i < next.length ; i++) {
if (i == 0) {
var t = getTimeRemaining(next[0].datetime);
$('.nextCity').text(next[0].title);
$('.nextCityPage').attr('href', next[0].btnDestinePage);
$('#futureDestinationBtn').attr('href', next[0].btnBuyNow);
$('#nextDays').text(t.days);
$('#nextHours').text(t.hours);
$('#nextMinutes').text(t.minutes);
if (t.days > 0) {
$('#nextDaysNavTop').html('o evento vai acontecer em <strong>'+ t.days +'</strong> dias');
}
else {
$('#nextDaysNavTop').html('<strong>amanhã</strong>');
}
}
else {
var t = getTimeRemaining(next[i].datetime);
console.log(next[i].title);
$('#commingSoonCity'+i).text(next[i].title);
$('#commingSoon'+i).text(t.days);
$('#commingSoonCityPage'+i).attr('href', next[i].btnDestinePage);
}
}
};
function getNextDestines(events_informations) {
var nextDestines = [];
var keys = Object.keys(events_informations);
for (var i = 0; i < keys.length; i++) {
var today = new Date();
var date = new Date(events_informations[keys[i]]['datetime']);
if (date.getTime() > today.getTime() && date.getDate() > today.getDate()) {
nextDestines = [events_informations[keys[i]], events_informations[keys[i+1]], events_informations[keys[i+2]], events_informations[keys[i+3]]];
break;
}
}
return nextDestines;
};
troque:
'datetime': 'June 20 2017 8:30:00 GMT-03:00'
por: