Igor's Blog

My travelblog.ws project is built as a responsive site so that I do not have to have a desktop and a mobile version of the site. Unfortunately some features are hard to implement generically and need a specific mobile version. One of these is the 'trip timeline'. On the desktop version it appears as a sidebar, on the mobile version it is a pop-over DIV that covers the whole page. The pop-over is triggered by pressing the 3-bar stack icon at the top of the page.

This is what the two versions look like...
respvistoggle_1.png

respvistoggle_2.png


My use cases were: 1. display the desktop sidebar for desktop sized pages 2. do not display any sidebar on mobile version 3. allow a toggle of the timeline on the mobile version only.



What I realised very quickly was that if I simply toggled the mobile version of my timeline that as soon as the browser window would be resized to 'desktop' size it would mess up my page because the mobile version of the timeline would still be visible.

So instead of using the jQuery toggle() method to toggle the mobile timeline DIV, I used the toggleClass() method instead. That required me to set up some CSS as follows:
 CSS
.mobile_popover {
display: none;
...
}
.mobile_visible {
display: none;
}
@media screen and (max-width: 768px) {
.mobile_visible {
display: block;
}
}


...and the HTML for the mobile timeline DIV is something like...
 HTML
<div class="mobile_popover">...</div>


The mobile timeline DIV has the mobile_popover class set, so it's not visible by default. The mobile_visible class is set up with a media query to only appear on the 'mobile' sized browser window.

A bit of JavaScript is then used to toggle the mobile timeline DIV on/off by toggling whether it has the mobile_visible class assigned like so...
 JavaScript
$('.mobile_popover').toggleClass('mobile_visible');


When toggled on, the mobile_visible class overwrites the 'display' property of mobile_popover so the timeline becomes visible.

Now if the mobile timeline is toggled on and the window is resized back to desktop size because the mobile_visible class is set to not being displayed on a 'desktop' sized window, the timeline will disappear. As soon as the window is resized back to 'mobile' size, the timeline appears again.

-i

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

Converting a CSV file containing commas in quotes to a pipe separated file using Awk and Bash

How to get Facybox gallery popup to work for images with dynamic URLs

jQuery UI Photoboxr plugin updated to version 0.2

Learn How to Add Disclaimer to All Outgoing Emails in Office 365

How to securely host your web site for free with Google Cloud and CloudFlare (part 3)

How to securely host your web site for free with Google Cloud and CloudFlare (part 2)

How to securely host your web site for free with Google Cloud and CloudFlare (part 1)

Beware of the subtle difference in date format strings between MySQL and SQLite

Postman reporting Unexpected 'N' error in response body

Adding extra shelves to the Ikea Detolf display cabinet

Recent Galleries

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Please follow me for more great content!
     
Don't show this again