I'm stuck at a very annoying problem, it's been bugging me since yesterday.
I have a script to hide my 'intro' by adding a class that contains 'display:none', when a user is still in the same session. Yet, my else if won't work whenever I refresh the page. Copying my code and pasting it in the console however, does work.
jQuery(function($) { // this does the trick and also makes sure jQuery is not conflicting with another library
if (!window.sessionStorage.gateIntro) {
$('.intro-wrapper').addClass('intro-wrapper--show');
$(document).on('click', '.intro-button', function(){
jQuery('.intro-wrapper').addClass('intro-wrapper--hide');
sessionStorage.gateIntro = 1;
setTimeout(function() {
$('.container').fadeIn('slow');
}, 1000);
});
// INTRO TIMER
setInterval(function(){
var random = Math.floor(Math.random() * 90 + 10);
var random2 = Math.floor(Math.random() * 90 + 10);
var random3 = Math.floor(Math.random() * 90 + 10);
var number = "<p class='number'>" + random + " </p>";
var number2 = "<p class='number'>" + random2 + " </p>";
var number3 = "<p class='number'>" + random3 + "</p>";
$('.intro-timer').empty().append(number, number2, number3);
}, 100);
}
else if (window.sessionStorage.gateIntro) {
console.log('there is a session key!');
$('.intro-wrapper').addClass('intro-wrapper--hidden');
$('.container').fadeIn('slow');
}
});
A few things to keep in mind;
- I'm using wordpress and angular, wordpress just as my API to fetch JSON
- I made sure my script.js is loaded after the rest of my js in my HTML
- Running this script normally does console log 'there is a session key!'
- It's only the .addClass() and .fadeIn() that doesn't work!
- .intro-wrapper--hide animates my div 150 viewport height to the top, .intro-wrapper-hidden sets it to display none
** EDIT **
My question was being downvoted due to someone thought it was a duplicate to another question about session storage not working ( sessionStorage isn't working as expected ) , but it has nothing to do with session storage, it doesn't run my addClass()
and fadeIn()
at all.
If someone could help me out and clear things up to me would be great :)
Thanks in advance!
` to see if that's the cause, but I imagine it is.
– Lionel Ritchie the Manatee Dec 30 '15 at 19:35