[英]how to change the layout theme color using framework7?
我想使用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>
在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');
}
我通過創建css文件在Framework7中創建了自定義顏色主題,在其中復制了負責創建紅色主題顏色的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;
}
這很簡單。 如果您不知道如何使用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');
如果要為背景或文本創建自定義顏色。 將顏色添加到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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.