使用带有Notify.js jQuery插件的外部自定义CSS

问题描述 投票:3回答:1

我刚刚开始学习jQuery和CSS,并且有一个关于使用特定jQuery插件Notify.js生成的样式转换/通知的问题。

插件网站上有文档但我无法正确理解如何限制我的JS文件中有关样式的代码量,而是将其保存在我的外部CSS文件中。看起来你应该能够为CSS类使用正确的命名约定,然后以一种简单的方式进行操作。

而不是

$.notify.addStyle('check', {
    html : "<div><span data-notify-text/></div>",
    classes : {
        base : {
        "white-space" : "nowrap",
        "background-color" : "#cccccc",
        "padding" : "5px",
        "font-family" : "Comic Sans MS"
        },
        uncheck : {
            "color" : "white",
            "background-color" : "#252525"
        }
    }
});

我想在我的外部CSS文件中使用这样的东西

.notifyjs-check-base { 
white-space: nowrap; 
background-color: #D3D3D3;/*lightgray*/ 
padding: 5px; 
font-family: Comic Sans MS;  }

.notifyjs-check-uncheck{
color: white,
background-color: #252525;}

然后就是这样的

$.notify.addStyle('check');

在我的js文件中使用我的通知样式。

所有这些都在Chrome扩展程序中用于向用户显示消息。

你会怎么做?让今天做好事,帮助初学者:)

javascript jquery css jquery-plugins styling
1个回答
1
投票

如果我正确理解你的问题,我想你想要分离你的javascript和css代码。然后你可以在你的javascript文件中写到这一点。

 $.notify.addStyle('foo', {
    html:
      "<div>" +
        "<div class='clearfix'>" +
          "<div class='title' data-notify-html='title'/>" +
          "<div class='buttons'>" +
            "<button class='no'>Cancel</button>" +
            "<button class='yes' data-notify-text='button'></button>" +
          "</div>" +
        "</div>" +
      "</div>"
});

和外部css文件中的其余css类

.notifyjs-foo-base {
 opacity: 1;
 width: 200px;
 background-color: #DFF0D8;
 color:#468847;
 border-color:#D6E9C6;
  padding: 5px;
  border-radius: 10px;
  font-weight:bold;
}

.notifyjs-foo-base .title {
  width: 100px;
  float: left;
  margin: 10px 0 0 10px;
  text-align: right;
}

.notifyjs-foo-base .buttons {
  width: 70px;
  float: right;
  font-size: 9px;
  padding: 5px;
  margin: 2px;
}

.notifyjs-foo-base button {
  font-size: 9px;
  padding: 5px;
  margin: 2px;
  width: 60px;
}
© www.soinside.com 2019 - 2024. All rights reserved.