我想使用framework7动态更改正文颜色。我尝试了包含framework7.css和framework7.js文件,但它没有用。
<link rel="stylesheet" href="css/framework7.material.css">
<link rel="stylesheet" href="css/framework7.material.colors.css">
<link href="http://fonts.googleapis.com/css?family=Roboto:400,300,500,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/kitchen-sink.css">
<script type="text/javascript" src="js/framework7.js"></script>
<script type="text/javascript" src="js/kitchen-sink.js"></script>
答案 0 :(得分:1)
在你的CSS中你应该定义背景颜色的类。例如,yellow-background
,red-background
和bluebackground
。
.yellow-background {
background: yellow;
}
etc.
然后在您的javascript中,应该根据单击按钮添加或删除该类。像这样:
$$('.some-button').on('click', function (e) {
$$('.some-div').removeClass('yellow-background');
$$('.some-div').removeClass('blue-background');
$$('.some-div').addClass('red-background');
}
答案 1 :(得分:1)
我在Framework7中创建了自定义颜色主题,创建了css文件,我已经复制了framework7.ios.colors.css
部分,负责创建红色主题颜色。将red
替换为我的自定义颜色opco
。
我对十六进制颜色#ff3b30
到#cbcc33
所做的一样。不要忘记搜索和替换短语ff3b30
,因为SVG元素的颜色不会改变。
这样做时,不要忘记将新创建的.css文件包含在html中:
<link rel="stylesheet" href="css/custom-color-theme.css">
我的css文件,其中包含Framework7的自定义颜色主题:
.color-opco {
color: #cbcc33;
}
.list-block .item-link.list-button.color-opco,
.tabbar a.active.color-opco,
a.color-opco {
color: #cbcc33;
}
.label-switch input[type="checkbox"]:checked + .checkbox.color-opco,
.label-switch.color-opco input[type="checkbox"]:checked + .checkbox {
background-color: #cbcc33;
}
.color-opco.button:not(.button-fill),
.color-opco.buttons-row .button,
.theme-opco .button:not(.button-fill) {
border-color: #cbcc33;
}
html:not(.watch-active-state) .color-opco.button:not(.button-fill):active,
html:not(.watch-active-state) .color-opco.buttons-row .button:active,
html:not(.watch-active-state) .theme-opco .button:not(.button-fill):active,
.color-opco.button:not(.button-fill).active-state,
.color-opco.buttons-row .button.active-state,
.theme-opco .button:not(.button-fill).active-state {
background-color: rgba(255, 59, 48, 0.15);
}
.color-opco.button:not(.button-fill).active,
.color-opco.buttons-row .button.active,
.theme-opco .button:not(.button-fill).active {
background-color: #cbcc33;
color: #fff;
}
.theme-opco .button.button-fill,
.button.button-fill.color-opco {
background: #cbcc33;
color: #fff;
}
.progressbar.color-opco span,
.progressbar.theme-opco span,
.theme-opco .progressbar span,
.progressbar.bg-opco span {
background-color: #cbcc33;
}
.progressbar-infinite.color-opco:before,
.progressbar-infinite.theme-opco:before,
.theme-opco .progressbar-infinite:before,
.progressbar-infinite.bg-opco:before {
background-color: #cbcc33;
}
.color-opco i.icon,
.theme-opco i.icon,
i.icon.color-opco,
i.icon.theme-opco {
color: #cbcc33;
}
i.icon-next.color-opco,
i.icon-next.theme-opco,
.theme-opco i.icon-next {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2015%2015'%3E%3Cg%3E%3Cpath%20fill%3D'%23cbcc33'%20d%3D'M1%2C1.6l11.8%2C5.8L1%2C13.4V1.6%20M0%2C0v15l15-7.6L0%2C0L0%2C0z'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
}
i.icon-prev.color-opco,
i.icon-prev.theme-opco,
.theme-opco i.icon-prev {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2015%2015'%3E%3Cg%3E%3Cpath%20fill%3D'%23cbcc33'%20d%3D'M14%2C1.6v11.8L2.2%2C7.6L14%2C1.6%20M15%2C0L0%2C7.6L15%2C15V0L15%2C0z'%2F%3E%3C%2Fg%3E%3C%2Fsvg%3E");
}
i.icon-back.color-opco,
i.icon-back.theme-opco,
.theme-opco i.icon-back {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2012%2020'%3E%3Cpath%20d%3D'M10%2C0l2%2C2l-8%2C8l8%2C8l-2%2C2L0%2C10L10%2C0z'%20fill%3D'%23cbcc33'%2F%3E%3C%2Fsvg%3E");
}
i.icon-forward.color-opco,
i.icon-forward.theme-opco,
.theme-opco i.icon-forward {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2012%2020'%3E%3Cpath%20d%3D'M2%2C20l-2-2l8-8L0%2C2l2-2l10%2C10L2%2C20z'%20fill%3D'%23cbcc33'%2F%3E%3C%2Fsvg%3E");
}
i.icon-bars.color-opco,
i.icon-bars.theme-opco,
.theme-opco i.icon-bars {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2021%2014'%3E%3Cpath%20fill%3D'%23cbcc33'%20d%3D'M0%2C0h2v2H0V0z%20M4%2C0h17v1H4V0z%20M0%2C6h2v2H0V6z%20M4%2C6h17v1H4V6z%20M0%2C12h2v2H0V12z%20M4%2C12h17v1H4V12z'%2F%3E%3C%2Fsvg%3E");
}
@media (-webkit-min-device-pixel-ratio: 2) {
i.icon-bars.color-opco,
i.icon-bars.theme-opco,
.theme-opco i.icon-bars {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2042%2026'%3E%3Cpath%20fill%3D'%23cbcc33'%20d%3D'M0%2C0h4v4H0V0z%20M8%2C1h34v2H8V1z%20M0%2C11h4v4H0V11z%20M8%2C12h34v2H8V12z%20M0%2C22h4v4H0V22z%20M8%2C23h34v2H8V23z'%2F%3E%3C%2Fsvg%3E");
}
}
.theme-opco a,
.theme-opco .item-link.list-button {
color: #cbcc33;
}
.theme-opco .tabbar a,
.tabbar.theme-opco a,
.theme-opco .tabbar a i,
.tabbar.theme-opco a i {
color: inherit;
}
.theme-opco .tabbar a.active,
.tabbar.theme-opco a.active,
.theme-opco .tabbar a.active i,
.tabbar.theme-opco a.active i {
color: #cbcc33;
}
.theme-opco .range-slider input[type="range"]::-webkit-slider-thumb:before,
.range-slider.theme-opco input[type="range"]::-webkit-slider-thumb:before {
background-color: #cbcc33;
}
.theme-opco .range-slider input[type="range"]::-ms-fill-lower,
.range-slider.theme-opco input[type="range"]::-ms-fill-lower {
background-color: #cbcc33;
}
.theme-opco label.label-checkbox input[type="checkbox"]:checked + .item-media i.icon-form-checkbox,
.theme-opco label.label-checkbox input[type="radio"]:checked + .item-media i.icon-form-checkbox {
background-color: #cbcc33;
}
.theme-opco label.label-radio input[type="checkbox"]:checked ~ .item-inner,
.theme-opco label.label-radio input[type="radio"]:checked ~ .item-inner {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2013%2010'%3E%3Cpolygon%20fill%3D'%23cbcc33'%20points%3D'11.6%2C0%204.4%2C7.2%201.4%2C4.2%200%2C5.6%204.4%2C10%204.4%2C10%204.4%2C10%2013%2C1.4%20'%2F%3E%3C%2Fsvg%3E");
}
.theme-opco .picker-calendar-day.picker-calendar-day-selected span {
background-color: #cbcc33 !important;
}
.swiper-pagination.color-opco .swiper-pagination-bullet-active,
.theme-opco .swiper-pagination .swiper-pagination-bullet-active {
background-color: #cbcc33;
}
.swiper-pagination.color-opco .swiper-pagination-progressbar,
.theme-opco .swiper-pagination .swiper-pagination-progressbar {
background-color: #cbcc33;
}
.swiper-pagination.swiper-pagination-progress.bg-opco {
background-color: rgba(255, 59, 48, 0.25);
}
.swiper-button-next.color-opco,
.swiper-container-rtl .swiper-button-prev.color-opco,
.theme-opco .swiper-button-next,
.theme-opco .swiper-container-rtl .swiper-button-prev {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M27%2C22L27%2C22L5%2C44l-2.1-2.1L22.8%2C22L2.9%2C2.1L5%2C0L27%2C22L27%2C22z'%20fill%3D'%23cbcc33'%2F%3E%3C%2Fsvg%3E");
}
.swiper-button-prev.color-opco,
.swiper-container-rtl .swiper-button-next.color-opco,
.theme-opco .swiper-button-prev,
.theme-opco .swiper-container-rtl .swiper-button-next {
background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg%20xmlns%3D'http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg'%20viewBox%3D'0%200%2027%2044'%3E%3Cpath%20d%3D'M0%2C22L22%2C0l2.1%2C2.1L4.2%2C22l19.9%2C19.9L22%2C44L0%2C22L0%2C22L0%2C22z'%20fill%3D'%23cbcc33'%2F%3E%3C%2Fsvg%3E");
}
.bg-opco,
.button.button-fill.bg-opco,
a.bg-opco,
.list-block .swipeout-actions-left a.bg-opco,
.list-block .swipeout-actions-right a.bg-opco {
background-color: #cbcc33;
}
.border-opco {
border-color: #cbcc33;
}
.list-block .border-opco.item-inner:after,
.list-block ul.border-opco:after,
.border-opco:after,
.list-block .border-opco.item-inner:before,
.list-block ul.border-opco:before,
.border-opco:before {
background-color: #cbcc33;
}
.badge.color-opco,
.badge.theme-opco {
background-color: #cbcc33;
color: #fff;
}
答案 2 :(得分:1)
这很简单。 如果您不知道如何使用DOM函数。 请检查一次=> 点击framework7-DOM!
或
如果您熟悉dom,只需更改任何CSS,就像:
$$('.classname').css({
left: '100px',
top: '200px',
color: 'red',
width: '300px',
marginLeft: '17px',
'padding-right': '20px'
});
您可以在此处使用所有CSS属性,如代码所示。 您根本不需要添加或删除类。
但是,如果您已经在该类上添加了要更改颜色的“重要”字样, 只需将CSS更改为:
this.$$('.appbg').attr('style', 'background-color: green !important');
答案 3 :(得分:0)
如果要为背景或文本创建自定义颜色。将您的颜色添加到framework7.material.colors.css:
//your custom background
.layout-bg-custom {
background-color: #fff;
}
//custom text color
.color-custom {
color: #ec325b;
}
//custom framework7 buttons
.theme-custom .button.button-fill {
background: #ec325b;
color: #fff;
}
类似地,你可以为不同的标签添加颜色,然后在HTML中将上面的类添加到你想要应用css的标签。
<button class="button button-fill theme-custom">F7 Footer button</button>
Framework7已经提供了一些主题颜色(您也可以添加到这些主题):http://framework7.io/docs/color-themes.html