0
嘗試提供更改徽標圖像的解決方案 - 用戶滾動到不同顏色區域。所以黑暗/光明的主題。當用戶在不同彩色部分滾動時徽標圖像更改
a)如何檢測用戶是否滾動到的部分是暗/淡色主題。 b)將徽標圖像切換到相反的調色板。
https://jsfiddle.net/atg5m6ym/6830/
$(document).ready(function() {
$(document).on('scroll', function() {
console.log("$(this).scrollTop()", $(this).scrollTop());
console.log("$('section').position().top", $('section').position().top);
if ($(this).scrollTop() >= $('section').position().top) {
//get current active section and acquire theme pallete
//console.log($(this));
//console.log($(this).data("theme"))
//yourActionHere();
}
})
});
section {
background: orange;
width: 100%;
height: 300px;
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<section data-theme="dark">test1</section>
<section data-theme="dark">test2</section>
<section data-theme="light">test3</section>
<section data-theme="dark">test2</section>
<section data-theme="light">test4</section>
<section data-theme="light">test5</section>
http://jsfiddle.net/n4pdx/289/
$(window).scroll(function() {
var hT = $('#scroll-to').offset().top,
hH = $('#scroll-to').outerHeight(),
wH = $(window).height(),
wS = $(this).scrollTop();
console.log((hT - wH), wS);
if (wS > (hT + hH - wH)){
alert('you have scrolled to the h1!');
}
});
section {
height: 800px;
background: red;
border: 1px solid black;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<section>Y</section>
<section>X</section>
<h1 id="scroll-to">I am The H1</h1>