嘿,我有一个让我紧张的问题,我不明白为什么会这样。我想在页面加载时,我的h1-tag得到类.load所以它淡入效果很好,问题是addClass不起作用,我的h1-tag永远不会得到类加载。请帮忙..?
脚本标记中的HTML和jQuery:
<!DOCTYPE html>
<html>
<head>
<title>New Era of Swegre</title>
<meta charset="UTF-8"/>
<link href='http://fonts.googleapis.com/css?family=Poiret+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Lato:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" type="text/css" href="css/home.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('.wrapper h1').addClass('load');
});
</script>
</head>
<body>
<div class="wrapper">
<h1>SWEGRE DESIGNS</h1>
</div>
</body>
</html>
CSS:
body
{background-color:black}
.wrapper
{
position: relative;
}
h1 {
opacity: 0;
color:white;
font-size: 21px;
text-align: center;
transition: opacity 1s ease-in;
}
.load {
color:white;
opacity: 1;
}
答案 0 :(得分:1)
使用以下内容替换您的代码,它将按您的意愿工作。
$(document).ready(function () {
$('.wrapper h1').addClass('load');
});
&#13;
.wrapper {
position: relative;
}
h1 {
opacity:0;
color:black;
font-size: 21px;
text-align: center;
transition: opacity 1s ease-in;
}
.load {
opacity: 1;
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="wrapper">
<h1>SWEGRE DESIGNS</h1>
</div>
&#13;