E
E
exactly the most2015-08-19 16:29:25
Raspberry Pi
exactly the most, 2015-08-19 16:29:25

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

5 answer(s)
M
Melkij, 2019-02-19
@melkij

A decent memory card, power supply, power cable, network cable.
What answer did you expect to see?

O
Oleg Krasavin, 2015-08-19
@okwinza

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...

A
Alexey Ukolov, 2015-08-19
@alexey-m-ukolov

How to add/remove link in head? And is it even possible?

W
WhiteSama, 2015-08-19
@WhiteSama

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+')'})
});

In the button in data-src prescribes the path to the background file.
Next, by clicking on the button, we write this path to the variable, and we write this path inline in the body.

R
rhost, 2015-08-19
@hoOstel

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 question

Ask a Question

731 491 924 answers to any question