September 30, 20179 yr Hi all, I have an SVG map and would like to have it so that when on a phone if a user taps a region the colour will change and remain that colour until another colour e.g. Region begins as #ff0000 When tapped changes to #ffff00 Stays that colour until another region is tapped Here is the map (towards the bottom of the page) - excuse how it looks on screens larger than 640px, right now I'm focusing on phones. And here's my CSS: a svg:focus #brackaghnorth { fill: #ff0000; pointer-events: none; } a svg:hover #tievebrack { fill: #ffff00; pointer-events: none; } a svg:hover #tievenameena { fill: #0000ff; pointer-events: none; } a svg:hover #liggins { fill: #ff3366; pointer-events: none; } a svg:hover #ligatraght { fill: #009900; pointer-events: none; } a svg:hover #keerin { fill: #ff00ff; pointer-events: none; } a svg:hover #oaghmonicrory { fill: #ff9900; pointer-events: none; } a svg:hover #teebaneeast { fill: #9933cc; pointer-events: none; } a svg:hover #carnanransy { fill: #ccff00; pointer-events: none; } a svg:hover #crouck { fill: #0033cc; pointer-events: none; } a svg:hover #alwories { fill: #00ffff; pointer-events: none; } a svg:hover #monanameal { fill: #cc0000; pointer-events: none; } a svg:hover #aghascrebagh { fill: #ccffff; pointer-events: none; } a svg:hover #crockanboy { fill: #ff9900; pointer-events: none; } a svg:hover #sheskinshule { fill: #ffff99; pointer-events: none; } a svg:hover #formil { fill: #33ff00; pointer-events: none; } a svg:hover #binnafreaghan { fill: #cc0000; pointer-events: none; } a svg:hover #cashel { fill: #9966ff; } a svg:hover #backan { fill: #00ff00; } a svg:hover #brackaghsouth { fill: #ffff00; } a svg:hover #leaghan { fill: #00ffff; } a svg #brackaghnorth, a svg #tievebrack, a svg #tievenameena, a svg #liggins, a svg #ligatraght, a svg #keerin, a svg #oaghmonicrory, a svg #teebaneeast, a svg #carnanransy, a svg #crouck, a svg #alwories, a svg #monanameal, a svg #aghascrebagh, a svg #crockanboy, a svg #sheskinshule, a svg #formil, a svg #binnafreaghan, a svg #cashel, a svg #backan, a svg #brackaghsouth, a svg #leaghan { transition: 200ms; transition-timing-function: ease-in-out; -webkit-transition: 200ms; -webkit-transition-timing-function: ease-in-out; } Edited September 30, 20179 yr by Demonolith
October 1, 20179 yr Author Have you tried adding values for :active (a:active) ? I tried the following, but it doesn't seem to work - it's for the uppermost region. a svg:hover #brackaghnorth { fill: #ff0000; pointer-events: none;} a svg:active #brackaghnorth { fill: #ff0000; pointer-events: none;}
October 1, 20179 yr I think this would have to be a jquery solution for example jQuery('button').click(function(){ jQuery(this).toggleClass('active'); });
October 1, 20179 yr Author I think this would have to be a jquery solution for example jQuery('button').click(function(){ jQuery(this).toggleClass('active'); }); Thanks Fuzzy Logic. I amended the code to what you see below, but I can only get it to work with one region - with multiple classes it mixes up the colors. jQuery('path').click(function(){ jQuery(this).toggleClass('tievenameena tievebrack brackaghnorth'); }); <!-- Brackagh North --> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="105px" width="100%" height="110px" viewBox="0 130 420 60" enable-background="new 0 0 1247.24 1360.63" xml:space="preserve"> <path class="brackaghnorth" fill="#ff0000" stroke="#000000" stroke-width="1" transform="translate(0,45)" d="M 360.25 72.1 Q 341.75 75.4 338.4 73.6 L 319.8 83.35 319.8 83.4 Q 321.55 86.6 323.5 89.8 325.2 92.7 326.9 95.45 328.6 98.3 330.15 101.3 331.85 104.35 332.95 107.1 334.1 109.85 334.65 111.4 335.25 112.85 336.5 115 337.85 117.15 339.15 120.1 339.95 122.05 341.6 124.3 342.9 126.1 342.5 127.55 342.05 128.95 342.05 130.7 342 132.4 342 133.9 341.95 135.4 339.8 136.2 337.55 137.05 336.4 135.95 L 351.35 163.1 Q 375.1 150.5 398.15 142.05 398.2 139.55 398.6 136.25 399.15 132.9 399.85 129.3 400.65 125.8 400.35 122.3 406.5 107 405.75 92.7 L 398.2 69.1 388.4 68 370.6 75.9 360.25 72.1 Z"></path> </svg> <!-- Tievebrack --> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="105px" width="100%" height="120px" viewBox="0 130 420 70" enable-background="new 0 0 1247.24 1360.63" xml:space="preserve"> <path class="tievebrack" fill="#ffff00" stroke="#000000" stroke-width="1" transform="translate(264,128)" d="M 69.95 23.7 Q 68.85 20.95 67.15 17.9 65.6 14.9 63.9 12.05 62.2 9.3 60.5 6.4 58.55 3.2 56.8 0 L 56.55 0 48.65 4.1 46.1 11.2 Q 33.6 21 28.95 24.8 26.1 27 22.25 28.75 20.35 29.45 16.95 32.75 13.35 36.1 11.1 37.4 8.75 38.65 2.65 44.25 1.25 45.35 0 46.5 6.05 52.3 7.95 54.1 9.65 55.8 13.7 59.2 17.75 62.6 20.55 66.15 23.4 69.7 24.4 71 25.35 72.3 26.3 73.85 27.1 75.4 29.6 77.6 32.1 79.85 33.35 81.1 34 81.8 34.95 82.65 37.05 84.85 40.45 87.9 L 49.15 88.7 50 88.2 75 86.65 Q 83.65 85.4 88.35 79.7 L 73.4 52.55 Q 74.55 53.65 76.8 52.8 78.95 52 79 50.5 79 49 79.05 47.3 79.05 45.55 79.5 44.15 79.9 42.7 78.6 40.9 76.95 38.65 76.15 36.7 74.85 33.75 73.5 31.6 72.25 29.45 71.65 28 71.1 26.45 69.95 23.7 Z"/></path> </svg> <!-- Tievenameena --> <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="105px" width="100%" height="165px" viewBox="0 130 418 116" enable-background="new 0 0 1247.24 1360.63" xml:space="preserve"> <path class="tievenameena" fill="#0000ff" stroke="#000000" stroke-width="1" transform="translate(0,45)" d="M 237.9 160.3 Q 238.3 161 239.1 162.15 239.85 163.25 240.6 164.25 241.25 165.4 241.9 166.4 242.45 167.4 244.95 170.65 247.35 173.95 249.55 178.75 251.75 183.4 252.6 184.4 253.4 185.45 254.5 186.35 255.6 187.3 259.35 190.9 259.2 191.6 259.7 192.7 261 194.85 260.55 195.25 259.95 195.85 259.45 195.95 258.9 195.95 259.3 196.75 259.65 197.5 260.9 200 262.1 202.45 263.75 205.25 265.3 208.1 266.35 210.65 267.35 213.1 267.85 213.25 268.5 212.9 269.9 212.3 271.15 211.75 271.85 211.35 275.8 209.25 278.5 207.65 281.2 205.95 283.7 202.75 286.3 199.4 288.15 195.8 289.9 192.25 291.25 190.45 292.5 188.6 293.65 187.35 L 302.2 178 312.15 172.1 303.45 171.3 Q 300.05 168.25 297.95 166.05 297 165.2 296.35 164.5 295.1 163.25 292.6 161 290.1 158.8 289.3 157.25 288.35 155.7 287.4 154.4 286.4 153.1 283.55 149.55 280.75 146 276.7 142.6 272.65 139.2 270.95 137.5 269.05 135.7 263 129.9 258.15 133.95 253.4 136.8 251.6 138.35 250.05 139.8 248.55 141.2 240.3 145.65 234.15 148.95 231.75 149.6 232.8 152.15 233.75 153.9 234.65 155.7 235.45 156.7 236.15 157.8 236.8 158.65 237.45 159.55 237.9 160.3 Z"></path> </svg> .brackaghnorth { fill: #ff8080; } .tievebrack { fill: #ffff80; } .tievenameena { fill: #8080ff; } Intended Results Region 1 #ff8080 to #ff0000 Region 2 #ffff80 to #ffff00 Region 3 #8080ff to #00ffff Actual Results Region 1 #ff8080 to #8080ff Region 2 #ffff80 to #8080ff Region 3 #8080ff to #ffff80 Edited October 1, 20179 yr by Demonolith
October 2, 20179 yr Have a read of this: http://api.jquery.com/toggleclass/ .toggleclass adds the class to the path. You have already called the class which is why it doesn't work. There may be a way to achieve what you want but I don't thinks it's going to be an easy fix (I'm not a jquery expert). Would it not be simpler to just display the map and list all the areas underneath. Google will like this and it's actually more useful for the parishioners.
October 2, 20179 yr Author Thanks fisicx. I had originally done the map using raphael.js and got it functioning as I intended with a hover effect that would bring up a few lines of text on each region, but I couldn't figure out a way to resize it and have it work responsively on all screens. Is there a way to do so? If there is then it would solve my issue. If you open this page and view it on any screen over 640px you'll see the original (almost) fully functional map. For each region I have the name of the townland along with the Irish translation and a descriptive line or 2 - I feel this would be too much content to put below the map (I currently just have the region names along with the corresponding colours via an SVG background).
October 2, 20179 yr It's never going to be responsive. The maps outlines are fixed points on the full sized map. Why would it be too much content to put under the map? Just add a link from the homepage to the map page and build the list. Make it richer and more useful by adding an image, links to a map, contact details and on.
October 2, 20179 yr If you don't mind the fill colour being removed when the user clicks on another part of the map, you can use :focus instead. Are you doing anything on screens below 640px to hide the content? It seems to scale okay, but you'll likely need to come up with a better interface to show the labels on a smaller screen.
October 2, 20179 yr If you don't mind the fill colour being removed when the user clicks on another part of the map, you can use :focus instead. Was just thinking grey out (mono) the other zones on focus and colour the selected would be a nice For using js for independent colour states then I would probably go for a data attributes approach to store the hover/focus colours and then grab the colour with data() but i'm no expert. Are you doing anything on screens below 640px to hide the content? It seems to scale okay, but you'll likely need to come up with a better interface to show the labels on a smaller screen. Totally agree here mate, was thinking maybe smaller screen click somehow expands the relevant map key and fills in the extra data? Or instead click the key and it highlights the map and shows info? Edit: Something like this sort of thing. Edited October 2, 20179 yr by BrowserBugs
October 2, 20179 yr Author Really sorry guys, but your suggestions are going over my head in terms of getting them to work. I like the idea of using focus to highlight only one region while leaving the others gray (however, if that would mean the map would initially be all gray I wouldn't be keen) - I thought focus only worked on input types? Should the desktop version of the map be scrapped altogether because it is a fixed width and height and therefore not responsive for different screen sizes? In terms of the amount of content, I would prefer to keep the hovering method as putting all townlands, translations and description up at once would be both confusing to read to the average user and cramped. I found these 2 Codepens in search of ideas... not sure how relevant they are. One Two I appreciate all the help!
October 2, 20179 yr How useful is this map to the parishioners? You seem to be putting a huge amount of effort into something that is a 'nice to have' feature that may be used once or twice then forgotten all about. To make it work as you want it needs a whole new set of code. And it's not ever going to display properly on small screens even if you do fix the hover thing, so why not just make it easy for yourself and just create new page with a list of the local areas. Sorry to be all negative but even on a desktop you have to guess where the boundaries lie, what towns and villages are in each area or the local roads that pass through these areas. It's great that you are doing all this for the parish but I'm not convinced about the value of this particular feature when there are far more fundamental issues need sorting (like making the site properly responsive and speeding up the very slow loading pages)
October 2, 20179 yr Author In all honesty, I'm not sure how important the map would be to parishioners. Around 10 years ago I offered to do a website for my parish and it has gradually been growing in size since. The site was originally created using tables and is a mess - to my shame that version is still live. One day I decided to redesign the whole site using CSS, this to me was a large undertaking but I wanted to teach myself CSS and stay ahead of the curve. Once I had done that Google announced that the search results would be based on how mobile-friendly sites were. I then added a mobile theme I customised to suit my own aesthetic, once that was done I realised responsive was the way to go and that's where I'm at now! I took this redesign on by myself without being asked to (the site is voluntary so no payment is exchanged), but I'm taking it as an opportunity to better myself in the field. The map is on the old site using Flash (eurgh) and I wanted to see if I could update it to include the same functionality.
October 3, 20179 yr So maybe drop the map for now and look at adding this at a later date. There are loads of ways you could improve this - one of which would be to superimpose the boundaries on a satellite image of the area.
October 3, 20179 yr In all honesty, I'm not sure how important the map would be to parishioners. I have that same feeling. I think to simplify you need to start with the content and work backwards to layout. Essentially you have data set you wish to offer the visitor about the Diocese of Derry; Place Name, Translation, Meaning. In addition you might want to show the visitor where each Diocese is located on a map for those who might not know. Now it's simply how to present that information; click maps, accordions etc are nice when you want to save space but they should enhance the visitors experience and not needlessly make them click. Start with a simple list then style it.
October 3, 20179 yr Author Thanks guys, I'm going to leave the map for now and come back to it at a later date. Right now I'll concentrate on making the site responsive (firstly on mobile, then on tablets) and figure out why my pages are loading so slowly (I imagine unused Javascript and 50+ plugins would be a factor - making the site properly responsive will negate a few plugins anyhoo). I'll keep this thread marked as unsolved as I'll likely return to it.
Create an account or sign in to comment