Yes, it is possible, but it would make it easier for us to help you if you shared, or better yet provided a demo (using jsFiddle.net) with some example code.
The switch/case detects the hash names. Change those to your desired hash names. I've set variables depending on what hash is detected. You can place any javascript in there. Functions, objects, whatever.
Like I said before I'm a novice so apologies for what is probably a mess of a code.
As I explained before I would basically like to have the yellow circle change colour as the user scrolls through the navigation menu. I figure the best way to do this would probably be to make use of a sprite with 3 different coloured circles.
Sorry to bother you guys discussion. Then, How can I add a class on the menu in according the URL in the browser? And again. I think we can just use CSS :target????
@Hompimpa why dont you create a separate thread for that and explain a little more with an example.
as for using :target - It isn't well enough supported to use for something that is 'required' on a web page. Also the javascript works on hash change - so its not necessary to click on an anchor link to change the hash, you can type it in yourself into the url bar, hit enter and it will change correctly. You could link someone with a custom hash and it will load with that hash 'enabled'.
if you type in the address bar, #contact and press enter, you're taken to the contact page, but the logo div doesn't change.
Can this be fixed?
One more little thing... (sorry :| )
I'm using 'transify' to fade in the bottom-borders below my navigation. Could a similar solution be applied to my logo div so it fades as it flicks through the different colours!?!?
It's working for me... perhaps it's happening in a specific browser? I'm using the latest version of Chrome and it looks like it's working in FF as well.
@jamy_za: Like the menu above. When you are on the forum page, the "forum menu" color will be changed. I think it was done by adding active class for example, on the menu based on the url. I think I've got the answer from Stackoverflow:
var path = window.location.href; // Just grabbing a handy reference to it $('ul a').each(function() { if (this.href === path) { $(this).addClass('active'); } });
I've tried it on chrome, safari and internet explorer.
If I have the 'contact' item selected in the menu. If I refresh the page, the content displayed will still be the 'contact' page but the logo flicks back to the first image used. I've changed the order of the images on the sprite and it keeps happening. Whatever the first image is, it's what automatically gets selected if the page is refreshed, or a page is accessed through the hash link.
I understand you guys have already helped me loads, but would really like to get this fixed. Really appreciate your efforts.
That fixes the revert to the first image when refreshing the page. It doesn't however update the logo when an item is accessed via a hash link. Is this not possible?
not being awkward, but I'm not 100% sure either and I'm sure Chris goes through everything you'll need to know, you'll just need to apply what we've spoken about using a method he uses!
"That fixes the revert to the first image when refreshing the page. It doesn't however update the logo when an item is accessed via a hash link. Is this not possible?"
I'm pretty sure I have included all the script you guys have suggested in this thread. I don't think any suggestions have updated the logo when accessing items through the hash url.
Just to clarify the '#serv' is just referring to what goes in ' href="" ' - within the HTML right?? I can see your code works in your demo, but for some reason It's not happening at my end. Must be the code.. or my slider maybe..
Also Mottie your method does allow me to refresh the page once accessed through a hash link and update the logo, but it doesn't do it automatically.
Could my slider have something to do with it?!
I appreciate all the time you guys have given me- thank you.
It's finally working - it's quite interesting to see how different methods achieve things in different ways.
Before, the change of logo would happen almost instantly after the click. It now happens with a delay which kinda coincides with the page load.
I realise I'm pushing it ever so slightly and should've probably started paying you guys a long time ago, but literally just a quick example of how a fade transition could be introduced to work with @jamy-za 's solution, would be extremely appreciated!
I'm a novice when it comes to CSS/jQuery but trying my best to pick it up fast..
I am using a slider as my main content box. I have 3 sections, each of which is accessible with a hash URL.
I was then wondering if it's at all possible to change the background of a random div (my logo), according to which hashURL (section) is selected?
Thank you
Would really appreciate some help on this!
Thanks
The switch/case detects the hash names. Change those to your desired hash names. I've set variables depending on what hash is detected. You can place any javascript in there. Functions, objects, whatever.
Jamy, really appreciate your help - however could I have some more information - Where would that code go? Where do I reference the background images?
Mottie, you're right.
I've uploaded my progress so far to http://www.carlosrios.co.uk
Like I said before I'm a novice so apologies for what is probably a mess of a code.
As I explained before I would basically like to have the yellow circle change colour as the user scrolls through the navigation menu. I figure the best way to do this would probably be to make use of a sprite with 3 different coloured circles.
Thank you so much!
thanks!
http://jsfiddle.net/jFyZ8/1/
using a sprite like you mentioned and jquery
http://jsfiddle.net/jFyZ8/3/
And again. I think we can just use CSS
:target????as for using :target - It isn't well enough supported to use for something that is 'required' on a web page. Also the javascript works on hash change - so its not necessary to click on an anchor link to change the hash, you can type it in yourself into the url bar, hit enter and it will change correctly. You could link someone with a custom hash and it will load with that hash 'enabled'.
Massive thanks to you both jamy_za and sheepysheep60, it's worked!
edit: I think i was a bit premature in my celebrations.
I've uploaded my progress to http://www.carlosrios.co.uk once again.
if you type in the address bar, #contact and press enter, you're taken to the contact page, but the logo div doesn't change.
Can this be fixed?
One more little thing... (sorry :| )
I'm using 'transify' to fade in the bottom-borders below my navigation. Could a similar solution be applied to my logo div so it fades as it flicks through the different colours!?!?
Thanking you muchly!
BTW - Loved the images you used Jamy :P
activeclass for example, on the menu based on the url. I think I've got the answer from Stackoverflow:If I have the 'contact' item selected in the menu. If I refresh the page, the content displayed will still be the 'contact' page but the logo flicks back to the first image used. I've changed the order of the images on the sprite and it keeps happening. Whatever the first image is, it's what automatically gets selected if the page is refreshed, or a page is accessed through the hash link.
I understand you guys have already helped me loads, but would really like to get this fixed. Really appreciate your efforts.
Carlos
Try this (demo):
Thanks for your help.
That fixes the revert to the first image when refreshing the page. It doesn't however update the logo when an item is accessed via a hash link. Is this not possible?
If it's not possible to update the logo when accessing an item through a hash link, then is it possible to have the change fade in?
http://css-tricks.com/video-screencasts/85-best-practices-dynamic-content/
not being awkward, but I'm not 100% sure either and I'm sure Chris goes through everything you'll need to know, you'll just need to apply what we've spoken about using a method he uses!
I'll give that a go, thanks for sharing.
In the meantime, anyone with a solution, PLEASE share it! (-:
Thanks
I provided that solution earlier.
Where!?!?
I'm pretty sure I have included all the script you guys have suggested in this thread. I don't think any suggestions have updated the logo when accessing items through the hash url.
Thanks again!
It's not working though? :(
Just to clarify the '#serv' is just referring to what goes in ' href="" ' - within the HTML right?? I can see your code works in your demo, but for some reason It's not happening at my end. Must be the code.. or my slider maybe..
Also Mottie your method does allow me to refresh the page once accessed through a hash link and update the logo, but it doesn't do it automatically.
Could my slider have something to do with it?!
I appreciate all the time you guys have given me- thank you.
I've used Chris' frog sprite as the background image =)
It's finally working - it's quite interesting to see how different methods achieve things in different ways.
Before, the change of logo would happen almost instantly after the click. It now happens with a delay which kinda coincides with the page load.
I realise I'm pushing it ever so slightly and should've probably started paying you guys a long time ago, but literally just a quick example of how a fade transition could be introduced to work with @jamy-za 's solution, would be extremely appreciated!
Thank you once again all.
Carlos