mandi224
asked on
slideToggle once on first page load, not again
I have two DIVs on my page:
My related CSS is:
What I want is for my page to load and display the main div, then slowly toggleSlide the expanded div, wait a few seconds, toggleSlide the expanded div closed again, and then after that point, the user can click on the main div to re-expand it. I HAVE this piece working using the following javascript:
The part I'm unsure how to do is that I only one the automatic slideToggle to happen the first time the user comes to the page (the homepage) if they're browsing around the site and come back to the homepage again, I don't want it to slideToggle automatically every single time. So I'm thinking I need to set a cookie or session variable...? How would I do something like this? It would be OK if they left the site and came back later and it automatically did the slideToggle again, but not on a single session visiting the site.
<div id="main">This shows all the time</div>
<div id="expanded">This shows when toggled open</div>
My related CSS is:
#main
{
background: #000099;
color: #FFF;
width: 960px;
height: 60px;
margin-top: 20px;
}
#expanded
{
background: #FFF;
width: 958px;
height: 300px;
border: 1px solid #000099;
display: none;
}
What I want is for my page to load and display the main div, then slowly toggleSlide the expanded div, wait a few seconds, toggleSlide the expanded div closed again, and then after that point, the user can click on the main div to re-expand it. I HAVE this piece working using the following javascript:
<script type="text/javascript">
$(document).ready(function () {
$('#expanded').delay(1000).slideToggle(1400);
$('#expanded').delay(5000).slideToggle(1000);
$("#main").click(function () {
$(this).next("#expanded").slideToggle(1000);
});
});
</script>
The part I'm unsure how to do is that I only one the automatic slideToggle to happen the first time the user comes to the page (the homepage) if they're browsing around the site and come back to the homepage again, I don't want it to slideToggle automatically every single time. So I'm thinking I need to set a cookie or session variable...? How would I do something like this? It would be OK if they left the site and came back later and it automatically did the slideToggle again, but not on a single session visiting the site.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
User pointed me in the right direction but did not provide specific code.
ASKER
I modified my code to look like this:
Open in new window
This works, and is setting the cookie properly, however, I'm unsure how to check for the cookie. This is what I tried, and it is not working. (Please forgive me; I'm not very good with javascript/jquery.)
Open in new window
With this on the page, and my cookies cleared, it doesn't execute the toggle or set the cookie.