Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Expanding/Contracting Div on click

Featured Replies

Hi

 

Basically I want to expand a div to fit content on click (preferably a button in the top right hand corner aligned with the heading) then contract on click from the same button but now its in the bottom right hand corner..... here's an illustrated example of what i want..

 

on page load.....

post-12493-0-35177200-1375095955_thumb.jpg

 

 

on click ......

post-12493-0-66065300-1375095971_thumb.jpg

 

 

i want it so u can constantly cycle through an 'open' or 'closed' div, not so its only able to be clicked once...

 

i hope this makes sense

 

Will

You can use a simple jQuery toggle() function for this. Here's a very basic example that I just put together quickly: http://jsfiddle.net/LyndseyB/5S4mH/

 

edit: This fiddle http://jsfiddle.net/AMzfe/ (not my own work) shows how to incorporate the use of images.

Edited by Lyndsey

Use jQuery:

 

$(document).ready(function(){
 $("#mydiv1").click(function(){
  $("#mydiv2").slideToggle("fast");
});
});

#mydiv1 would be the Upcoming Events bar and #mydiv2 would be the information. It'd be best if you encased the info div inside #mydiv1, so it just expands the #mydiv1 instead of creating a whole new div beneath it. Make sure you set #mydiv2 to this in the CSS:

 

#mydiv2{
    display: none;
}

Hope this helps.

  • Author

Thanks for the fast replies, really helpful and very appreciative, gunna go with Lyndseys fiddle cheers :)

What would be the JScript equivalent, of the jQuery version ?

 

Lyndsey and I clearly wrote they're both jQuery, which is JavaScript. :)

  • 7 months later...

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.