简体   繁体   中英

Change site background colour with colour picker

I'm using this colour picker for my site. What I need to do is to change background of my website body/html when selection is in progress. Just like it changes the background of textbox there.

I've looked at the JS file itself but found it a bit complex. I added document.body.style.background = styleElement.jscStyle.backgroundColor; between lines 410 - 430 but nothing changed.

How can I achieve it.

Thanks

In section 8 of the Demos page you have "Onchange event":

You need to create the input like this:

<input class="color"
    onchange="document.body.style.backgroundColor = '#'+this.color">

My guess is that in your example you have forgot to add # before the color HEX code.

Add a class ( .colorPicker ) to the color picker input field and then do this in jQuery:

'use strict';
$(document).ready(function(){
    $(".colorPicker").change(function(){
        $('body').css('background-color', $(this).css('background-color'));
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM