简体   繁体   中英

JQuery UI - Slider change opacity on slide - Error

I'm trying to use a JQueryUI slider to control the opacity of an element with the id "main-lights", but this script causes an error.

$("#slider-lamps").slider({
orientation: "vertical", 
range: "min",
value: 50,
min: 0,
max: 100
slide: function( event, ui ) {
    $( "#main-lights" ).css( "opacity", ui.values[ 0 ]);
}
});

This version works fine:

$("#slider-lamps").slider({
orientation: "vertical", 
range: "min",
value: 50,
min: 0,
max: 100
});

Can I not use a variable as the second jquery .css parameter?

How can I write this properly?

You are missing a , after max:100 in your first code segment.

$("#slider-lamps").slider({
    orientation: "vertical", 
    range: "min",
    value: 50,
    min: 0,
    max: 100,
    slide: function( event, ui ) {
        $( "#main-lights" ).css( "opacity", ui.values[ 0 ]);
    }
});
$("#slider-lamps").slider({
orientation: "vertical", 
range: "min",
value: 50,
min: 0,
max: 100**,**
slide: function( event, ui ) {
    $( "#main-lights" ).css( "opacity", ui.values[ 0 ]);
}
});

You missed a "," after max:100

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