+ Reply to Thread
Results 1 to 5 of 5

Thread: Visibility W/ Ajax

  1. #1
    Junior Member
    Join Date
    Jun 2006
    Posts
    46

    Default Visibility W/ Ajax

    I want to display some information on a page, but only until a user chooses not to. For example, I'd like to have some text in a table row, then a user clicks "close" and then the text disappears, but the rest of the page moves up on the page to fill the space. If the user then clicks something, I'd like the text to show back up. I know I can do this with simply filling a div or span with nothing, but I was wondering if there's a better way with CSS or something. Please nothing with frameworks!! Thanks!
    If it helps, I'd like this for my user article app, http://www.naturesmagazine.com/membe...cles/index.php , so the user can hide and show their search results while viewing articles.
    Last edited by phpnut; 11-09-2006 at 01:58 PM.
    My ongoing projects...
    www.naturesmagazine.com
    www.energyreform.org *new domain*
    www.photographyavenue.com
    ----
    You may also remember me as imnewtophp...

  2. #2
    Forum Leader
    Join Date
    Jul 2005
    Location
    Leeds, England
    Posts
    648

    Smile Re: Visibility W/ Ajax

    If you use scriptaculous effects, it's possible to make a page where the user can show and \ or hide parts of the page with AJAX.
    This is what I'm using, and it works fairly well:
    HTML Code:
    <!-- in your head section: -->
    <script src="/javascripts/prototype.js" type="text/javascript"></script>
    <script src="/javascripts/effects.js" type="text/javascript"></script>
    
    <!-- The toggle link: -->
    <a href="#" onclick="Effect.toggle('info','blind',{});; return false;" title="Toggle this sections visibility">Toggle this</a>
    
    <!-- The element to be toggled: -->
    <div id="info" class="someclass">
    Your content here!
    </div>
    To get that working, download the scriptaculous javascript library and extract it to somewhere like sitepath/javascripts/.
    Prototype is included with Scriptaculous, so there's no need to download it on it's own.
    If you want the element to be hidden by default, give it CSS properties of display: none;, but make sure they are applied using the style="display: none" method rather than a stylesheet entry and a class as this works off of the CSS attributes of an element.

    The effect can be either blind, which appears to pull the element down (content doesn't move with it), appear (fades in and out) or slide (like blind, but the content moves with the element).
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!

  3. #3
    Junior Member
    Join Date
    Jun 2006
    Posts
    46

    Default Re: Visibility W/ Ajax

    Thanks, Nuvo! I was a little weary about ajax frameworks because I could never figure out how to use them, but since you showed me how to use it, I tried it out and it worked very nicely!
    My ongoing projects...
    www.naturesmagazine.com
    www.energyreform.org *new domain*
    www.photographyavenue.com
    ----
    You may also remember me as imnewtophp...

  4. #4
    Junior Member
    Join Date
    Jun 2006
    Posts
    46

    Exclamation Re: Visibility W/ Ajax

    I have one more question which is probably really obvious, but how can I have the div start out being hidden and then have the user click the link or button and have the content flow down?
    My ongoing projects...
    www.naturesmagazine.com
    www.energyreform.org *new domain*
    www.photographyavenue.com
    ----
    You may also remember me as imnewtophp...

  5. #5
    Forum Leader
    Join Date
    Jul 2005
    Location
    Leeds, England
    Posts
    648

    Smile Re: Visibility W/ Ajax

    If you don't want the box shown by default, you simply change it from:
    HTML Code:
    <div id="toggleme">Something</div>
    To:
    HTML Code:
    <div id="toggleme" style="display: none;">Something</div>
    Using display: none; will make the element invisible, meaning that when the toggle link is clicked, it will be shown rather than being visible and then hidden.
    If you want the content to appear as though it's moving when the element is shown, simply change "blind" to "slide".
    PHP, CSS, XHTML, Delphi, Ruby on Rails & more.
    Current project: CMS Object.
    Most recent change: Theme support is up and running... So long as I use my theme resource loaders instead of that in the Rails plug-in.
    Release date: NEVER!!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. AJAX Loading Message
    By phpnut in forum Javascript
    Replies: 2
    Last Post: 11-29-2006, 12:03 PM
  2. My First (Almost)Completed Ajax Project
    By phpnut in forum Javascript
    Replies: 4
    Last Post: 11-07-2006, 11:42 AM
  3. Searching With Ajax
    By phpnut in forum Javascript
    Replies: 5
    Last Post: 11-06-2006, 07:56 AM
  4. AJAX and PHP
    By phpnut in forum PHP
    Replies: 4
    Last Post: 10-02-2006, 01:22 PM
  5. Submitting Forms With Ajax
    By phpnut in forum PHP
    Replies: 0
    Last Post: 10-01-2006, 11:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts