Don't overwrite css properties, but add to them with jQuery

后端 未结 3 563
情歌与酒
情歌与酒 2021-01-23 00:29

I just want to know how to use the jquery .css() function to not overwrite, but to add additional values to css properties.

For instance, I have an element that is curre

3条回答
  •  轮回少年
    2021-01-23 00:47

    Save the current style, then concatenate:

    var rotation = 0;
    function rotate() {
        rotation += 90;
        var rotationString = 'rotate(' + rotation + 'deg)';
        var current = $('#square').css('transform');
        $('#square').css('transform', current +' '+ rotationString);
    }
    

    http://jsfiddle.net/oqqubda8/

    It works, and I don't know if there's another way to do it.

提交回复
热议问题