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

, ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

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

Recent Blog Posts

How to install Panel Glide Blinds from Blinds Online

Showing whitespace characters in vi

Using Jackson to automatically convert Java POJOs to JSON as output of a Jersey service

Enable quick access to the keyboard and emoji viewer in macOS

How to tell if your site is served via CloudFlare

Googe Cloud Platform doesn't support CloudFlare's free edge certificates

Fixing the invalid private key error in the Google Cloud Platform App Engine app Settings page

Cleaning the sticky PlayStation controller analogue thumb sticks

Invoking interactive shell scripts non-interactively

Using variables as column numbers with Bash and Awk when processing text files

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

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again