[英]How to add a css propery on click event using backbone js
I am trying to add a css property after a click event in backbone js.when i click the .hero-content div i need to add a background color to hero-content div.Here is my event 我正在尝试在主干js中的click事件后添加css属性。当我单击.hero-content div时,我需要为hero-content div添加背景色。这是我的事件
events: function () {
if (vc.app.currentDevice.minWidth >= 769 && !!Modernizr.video) {
return {
'click .hero-content': 'heroToggled',
'mouseenter .hero-content': 'NewGroup'
};
}
return {};
},
and function 和功能
heroToggled: function (evt) {
var $heroContent = $(evt.currentTarget);
var $backgroundToActivate = $heroContent.siblings('.hero-background');
this.$backgrounds.css({
opacity: 0,
filter: 'alpha(opacity=0)'
});
$backgroundToActivate.css({
opacity: 1,
filter: 'alpha(opacity=100)'
});
},
render: function () {
this.$backgrounds = this.$('.hero-background');
return this;
}
Here what i need is when i click the .hero-content div i need to add a background color to hero-content div like below 这是我需要的,当我单击.hero-content div时,我需要为hero-content div添加背景颜色,如下所示
html:not(.is-page-editor) .pdp-hero-group .fullscreen-hero:first-child .hero-content{
border-color: #fff;
background-color: rgba(255,255,255,.05);
}
I have tried like below but it is not working 我已经尝试过如下所示,但无法正常工作
this.$backgrounds1.css({
bordercolor: '#fff',
backgroundcolor: 'rgba(255,255,255,.05)'
});
render: function () {
this.$backgrounds = this.$('.hero-background');
this.$backgrounds1 = this.$('.hero-content');
return this;
}
How to achieve this using backbone js? 如何使用骨干js实现这一目标?
From the fine jQuery css
manual : 从精美的jQuery css
手册中 :
Also, jQuery can equally interpret the CSS and DOM formatting of multiple-word properties. 同样,jQuery可以平等地解释多字属性的CSS和DOM格式。 For example, jQuery understands and returns the correct value for both
.css( "background-color" )
and.css( "backgroundColor" )
. 例如,jQuery理解并返回.css( "background-color" )
和.css( "backgroundColor" )
的正确值。 This means mixed case has a special meaning,.css( "WiDtH" )
won't do the same as.css( "width" )
, for example. 这意味着混合大小写具有特殊含义,例如,.css( "WiDtH" )
与.css( "width" )
。
So if you want to change the background-color
property, you need to say: 因此,如果要更改background-color
属性,则需要说:
this.$backgrounds1.css({
backgroundColor: 'rgba(255,255,255,.05)'
// -------^
});
or 要么
this.$backgrounds1.css({
'background-color': 'rgba(255,255,255,.05)'
// -^----------^-----^
});
Similarly for border-color
. 同样对于border-color
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.