Jump to content

man5

Members
  • Posts

    173
  • Joined

  • Last visited

Community Answers

  1. man5's post in Php page redirect doesn't save sessions. was marked as the answer   
    It seems like the sessions are now being saved, despite redirecting to another page. I didn't change anything.  I guess the online servers need a bit of time to be updated.
  2. man5's post in Quick question regarding showing and hiding div with click of button was marked as the answer   
    Alright I've solved by second issue.  This is the new code.
    $(document).ready(function($){ //PROCESS A TITLE BUTTON CLICK $(".mobile-collapse__title").click(function(e) { e.preventDefault(); if($(this).next('div.mobile-collapse__content').css('display') == 'none') { $('.mobile-collapse__content:visible').hide(); $(this).next('div.mobile-collapse__content').show(); } else { $('.mobile-collapse__content:visible').hide(); } }); }); @media (max-width: 767px) { .mobile-collapse__content { display: none; } }
  3. man5's post in Can anyone show me how to add "days" to this code? was marked as the answer   
    So I have it finally working.  Someone else helped me out.   There was a small mistake in the above code. 
     
    Here is the full working code.
    function Timer(container, timeLeft) { // get hour, minute and second element using jQuery selector var daysContainer = $(container).find('.day'); var hoursContainer = $(container).find('.hour'); var minsContainer = $(container).find('.min'); var secsContainer = $(container).find('.sec'); // hold time left var currentTimeLeft = timeLeft; // 1 second = 1000 ms var secondsForTimer = 1000; // hold ID value return by setInterval() var timerInterval; // call setInteval() only when timeLeft is greater than 0 if (currentTimeLeft == 0) { return; } else { //Call setInterval()function and store ID value to timerInterval. timerInterval = setInterval(countdown, secondsForTimer); } //function being passed to setInterval() function countdown() { currentTimeLeft = parseInt(currentTimeLeft - secondsForTimer); if (currentTimeLeft == 0) { //stop calling countdown function by calling clearInterval() clearInterval(timerInterval); return; } else { //calculate hours left var wholeSeconds = parseInt(currentTimeLeft / 1000,10); var wholeMinutes = parseInt(currentTimeLeft / 60000,10); var wholeHours = parseInt(wholeMinutes / 60,10); var wholeDays = parseInt(wholeHours / 24,10); //calculate hours left var hours = parseInt(wholeHours % 24,10); //calculate minutes left var minutes = parseInt(wholeMinutes % 60,10); //calculate seconds left var seconds = parseInt(wholeSeconds % 60,10); //prefix 0 to hour, min and second counter $(daysContainer).text((wholeDays < 10 ? "0" : "") + wholeDays + (wholeDays <=0 ? " day" : " days")); $(hoursContainer).text((hours < 10 ? "0" : "") + hours + (hours <=0 ? " hr" : " hrs")); $(minsContainer).text((minutes < 10 ? "0" : "") + minutes + (minutes <=0 ? " min" : " mins")); $(secsContainer).text((seconds < 10 ? "0" : "") + seconds + (seconds <=0 ? " sec" : " secs")); } } }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.