【发布时间】:2015-10-14 20:06:33
【问题描述】:
我已经看过here,并尽我所能使用了那里提供的东西,但它真的没有帮助。
我试过this,但也没有用。
这是我的 JQuery(没有完成案例,但我的案例是我需要的):
$(document).ready(function(){
$("#sub").click(function(){
var initial = $('#name').val().substr(0, 1);
var name = $('#name').val();
switch(initial) {
case "K":
$("body").css("background-image", "url(background2.png)");
$("div").css("background-color", "#eee5e5");
$(".img").css("display", "none");
$(".me").css("padding-top", "100px");
$(".me").css("padding-bottom", "100px");
$(".me").css("color", "#570000");
$("p").css("font-family", "rebel");
$("a").css("font-family", "rebel");
$("#h1").css("font-family", "highway");
break;
}
});
});
我在 CSS 中的#h1(我的 p 和 a 标签还没有 css):
#h1{
background-color:#ef6d3a;
border-style:solid;
border-color:white;
border-width:3px;
font-family:hobo;
margin-top:10px;
margin-bottom:0px;
width:1224px;
right: 10;
}
还有我导入的字体:
@font-face{
font-family:peignot;
src:url(peignot.ttf);
}
@font-face{
font-family:binner;
src:url(ufonts.com_binner.ttf);
}
@font-face{
font-family:rebel;
src:url(rb.ttf);
}
@font-face{
font-family:highway;
src:url(hth.ttf);
}
@font-face{
font-family:hobo;
src:url(ufonts.com_hobo.ttf);
}
每当我运行这个函数时,除了字体之外的一切都会改变。我做错了什么,我需要做什么?
【问题讨论】:
-
在 jQuery 中使用时,样式通常不是驼峰式吗?例如字体家族?
-
没关系。这似乎无关紧要。您的 TTF 文件是否正确解析?
-
如果你知道所有这些样式将是什么,切换类而不是内联样式会更简单,看起来更干净......撤消更简单
-
@Kris Oye 是的,他们做到了,他们在 CSS 中也可以工作
标签: jquery css font-family