0

我想使用 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>
4

4 回答 4

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');
于 2019-05-09T11:29:46.020 回答
1

CSS

在您的 css 中,您应该定义背景颜色的类。例如yellow-backgroundred-backgroundbluebackground

.yellow-background {    
    background: yellow;
}
etc.

JS

然后在您的 javascript 中,应根据单击按钮添加或删除该类。像这样的东西:

$$('.some-button').on('click', function (e) {
    $$('.some-div').removeClass('yellow-background');
    $$('.some-div').removeClass('blue-background'); 

    $$('.some-div').addClass('red-background'); 
}
于 2015-10-28T09:36:04.797 回答
1

我通过创建css文件在Framework7中创建了我的自定义颜色主题,我将framework7.ios.colors.css负责创建红色主题颜色的部分复制到该文件中。替换red为我的自定义颜色,即opco.

我对十六进制颜色所做的#ff3b30相同#cbcc33。不要忘记搜索和替换短语ff3b30,因为 SVG 元素的颜色不会改变。

这样做时,不要忘记通过以下方式将新创建的 .css 文件包含到 html 中:

<link rel="stylesheet" href="css/custom-color-theme.css">

我的带有适用于 Framework7 的自定义颜色主题的 css 文件:

.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;
}
于 2016-10-21T10:02:22.753 回答
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

于 2016-05-06T05:34:54.030 回答