最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Modify properties of a CSS class directly using knockout 'data-bind' - Stack Overflow

programmeradmin0浏览0评论

I would like to modify properties of a CSS class directly using knockout 'data-bind', without using JQuery css() method.

I have a ponent (bootstrap slider) on which I want to set the background color depending on the slider value. On his homepage, the author is doing it by calculating rgb ponents and then applying them with jquery css() method.

Can I data-bind properties inside a css class with knockout or must I stick with JQuery css ()?

Edit: I want to change the background-color of a part of the ponent, described in a css class, not the background of the whole ponent.

I would like to modify properties of a CSS class directly using knockout 'data-bind', without using JQuery css() method.

I have a ponent (bootstrap slider) on which I want to set the background color depending on the slider value. On his homepage, the author is doing it by calculating rgb ponents and then applying them with jquery css() method.

Can I data-bind properties inside a css class with knockout or must I stick with JQuery css ()?

Edit: I want to change the background-color of a part of the ponent, described in a css class, not the background of the whole ponent.

Share Improve this question edited Jan 8, 2017 at 12:45 chrki 6,3336 gold badges38 silver badges59 bronze badges asked May 31, 2013 at 15:34 disco beatdisco beat 1882 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

jQuery css set's style properties on the element directly. This is the same as what the style binding does in Knockout: http://knockoutjs./documentation/style-binding.html. So, you should be able to use the style binding to acplish your task.

You can use a data-bind similar to this one:

data-bind="style: { background-color: colorRed() ? 'red' : 'black' }"

By changing the value in colorRed(), you can change to color to red or black. It is also possible to use something like this:

data-bind="style: { background-color: myColor() }"

Where myColor() return a hex color.

Be sure to use backgroundColor instead of background-color You can use this:

data-bind="style: { backgroundColor: color }"
发布评论

评论列表(0)

  1. 暂无评论