0
我一直未能找到有效的答案。我發現了一個類似問題的解決方案,但解決方案似乎並不奏效。JQuery在預覽版中運行,但不能在Tumblr上運行
我試圖使頁面向下滾動時頁眉的背景發生變化。它在Tumblr的預覽中運行得很好,但是當我進入實時頁面時它不起作用。
Here's an image demonstrating what I'm trying to accomplish。
這裏是我的HTML:
<div class="titlor"><a href="/">Don<i>'</i>t Hug Me I<i>'</i>m Scared</a></div>
...我的CSS:
.titlor {
font: normal normal bold 40px/40px 'Dhmis', cursive;
height:auto; width:100%;
background:transparent center/cover;
border-bottom:5px solid transparent;
position:fixed;
top:0; left:0;
text-transform:uppercase;
letter-spacing:1.5px;
text-align:center;
padding:10px;
z-index:100;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-ms-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
.titlor a {
color:white!important;
-webkit-transition: all 0.2s ease-in-out!important;
-moz-transition: all 0.2s ease-in-out!important;
-ms-transition: all 0.2s ease-in-out!important;
-o-transition: all 0.2s ease-in-out!important;
transition: all 0.2s ease-in-out!important;
}
.titlor i {
margin-left:-5px;
margin-right:7px;
color:white!important;
}
.titlor i:hover {
color:white!important;
}
.titlor.active {
background:#7acdc7 url('http://i.imgur.com/x3l1mP1.png') center/cover;
border-bottom:5px solid white;
}
...我的jQuery代碼。這被放置在結束標記之上。
<script>
$(document).ready(function() {
$(window).on("scroll", function() {
if($(window).scrollTop() > 25) {
$(".titlor").addClass("active");
} else {
//remove the background property so it comes transparent again (defined in your css)
$(".titlor").removeClass("active");
}
});
});
</script>
請記住,我不太瞭解JQuery和JS,我仍然只是在學習。我發現這個代碼不在這裏;我沒有自己輸入。
謝謝你的幫助。 :]
差點忘了,here's the blog I'm trying to do this on。
它的工作!我不確定我是如何忽視這一點的,但我想我是這麼做的。謝謝! –