Answer the question
In order to leave comments, you need to log in
What is the best way to implement site style change?
Can't figure it out, need help.
You need to change the style of the site (in my case, only the background), but do it at the user's choice, by pressing a button.
There is a crutch option, make a link with the desired style, and sew it into the menu.
But I want to make it more elegant so that only styles are connected. And I can't figure out how to do it.
Answer the question
In order to leave comments, you need to log in
A decent memory card, power supply, power cable, network cable.
What answer did you expect to see?
By clicking on the button, a function in JS is called, which writes the id / name of the style / class to the cookie and then replaces the desired style / class. Well, on loading the page, we check if there is anything in this cookie and load the style on it.
www.thesitewizard.com/javascripts/change-style-she...
How to add/remove link in head? And is it even possible?
If the user does not download bg, but uses pre-installed ones (scripts using jquery):
<body style="background: url(img/123.jpg)">
<button data-src="img/1234.jpg"></button>
</body>
$('button').on('click', function(){
var src = $(this).attr('data-src');
$('body').css({background: 'url('+src+')'})
});
If the backgrounds are prepared in advance, then you can make classes for this, if not, then it's better to throw inline in the body.
After selecting the background, throw in the body "style" with the necessary styles, remember the styles for the user (there is no point in using cookies, because there are accounts and they will be enough)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question