我想知道是否可以根据 Tumblr 中的标签渲染背景?
我的意思是,我发布关于一般生活和我喜欢的系列丛书,我希望当我发布关于生活的名言时,背景颜色是黑色,当我发布关于这本书的名言时,背景颜色为蓝色。
这可能吗?如果可能,怎么做?
最佳答案
您可以将自定义属性或类添加到要使用 jQuery 更改其背景的元素,如下所示:
$(document).ready(function(){
var tag = $('select the element where your tag is').text();
/*If there are more than one tag you'll have to work with
the string to select //only the one you want, maybe with
a switch if you have a limited number of options*/
$('body').addClass(tag);
})
然后,使用 css,您可以使用这样的选择器更改它:
body.tag{
background: #yourcolor;
}
关于javascript - 基于 Tumblr 标签渲染背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29917187/