Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Reverse the closing div
Old 11-03-2008, 01:10 AM Reverse the closing div
Skilled Talker

Posts: 94
Trades: 0
I have been using this JQuery script to have an opening and closing DIV. It works perfectly.(I forgot where I got it in order to give credit).

However, it is set up with the DIV being automatically open. I am trying to figure out how to have it automatically closed.

Code:
$(document).ready(function() {

    // When the expand button is clicked:
    $('.expandLeft').click(function() {
        $('.expandLeft').css("display","none");
        $('.collapseLeft').css("display","block");
        $('#menu').animate({height:"150px"},1550);
        $.cookie('menu', 'expanded');
    });
    // When the collapse button is clicked:
    $('.collapseLeft').click(function() {
        $('.collapseLeft').css("display","none");
        $('.expandLeft').css("display","block");
        $('#menu').animate({height:"1px"},1550);
        $.cookie('menu', 'collapsed');
    });


// COOKIES
    // DIV state
    var poster = $.cookie('menu');

    // Set the user's selection for the DIV
    if (poster == 'collapsed') {
        $('.collapseLeft').css("display","none");
        $('.expandLeft').css("display","block");
        $('#menu').css("height","1px");
    };

});
IG88 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-03-2008, 04:25 AM Re: Reverse the closing div
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
call the opposite function on loading the document
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-03-2008, 08:05 AM Re: Reverse the closing div
Skilled Talker

Posts: 94
Trades: 0
Well there is no call in the document. Just the js script calls. The js file just finds the Div name.
IG88 is offline
Reply With Quote
View Public Profile
 
Old 11-03-2008, 11:52 AM Re: Reverse the closing div
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
in that case, call the collapse function on page load.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-03-2008, 12:28 PM Re: Reverse the closing div
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Or, you could give the element an inline style of display: none and height: 1px, since all the function is doing is animating those CSS properties.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 11-03-2008, 12:50 PM Re: Reverse the closing div
Skilled Talker

Posts: 94
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
Or, you could give the element an inline style of display: none and height: 1px, since all the function is doing is animating those CSS properties.
This does actually work the way you are thinking, but the problem is that when you first load the page the JS is looking at the DIV as Open so the open/close function shows "close" when the Div is not even visible because of the CSS you recommended.



Quote:
Originally Posted by chrishirst View Post
in that case, call the collapse function on page load.
Chris. You are right.
I tried this,
<script type="text/javascript">
function collapseLeft()
</script>

Of course it doesn't work. What am I doing wrong here?
IG88 is offline
Reply With Quote
View Public Profile
 
Old 11-03-2008, 12:53 PM Re: Reverse the closing div
Skilled Talker

Posts: 94
Trades: 0
Quote:
Originally Posted by wayfarer07 View Post
Or, you could give the element an inline style of display: none and height: 1px, since all the function is doing is animating those CSS properties.
I should have also explained before that I have an alternating text depending on the state of the div. When the div is closed the text reads "open menu" and of course when it is open then the text says "close menu".
IG88 is offline
Reply With Quote
View Public Profile
 
Old 11-03-2008, 03:29 PM Re: Reverse the closing div
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
<script type="text/javascript">
function collapseLeft()
</script>

What am I doing wrong here?
There you have (almost) defined a new function called collapseLeft()

use
Code:
<script type="text/javascript">
collapseLeft()
</script>
between the </body> & </html> elements.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 11-03-2008, 06:58 PM Re: Reverse the closing div
Skilled Talker

Posts: 94
Trades: 0
Unfortunately that does not work.
IG88 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Reverse the closing div
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.27108 seconds with 12 queries