私は以下のコードを使用して、特定の要素のスクロール速度を変更しています。コードHEREからコピーしました。jQueryでデータスクロール速度を変更しますか?
私の全体的なコードを再確認するには、 ".slogan-a-line"に色の変更を加えました。
if/elseは、「#image-ul」がブラウザウィンドウの下端よりも上にあるかどうかによって異なります。
私の問題は、ブラウザウィンドウのサイズを変更したりスクロールしたりするとき、「.slogan-a-line」の色が変わるが、他の要素のデータスクロール速度は変わらないということです。彼らが(再)積み込みをするとき。
最初にウェブページを読み込んだとき、正しいデータスクロール速度がコードによって設定されます。しかし、ブラウザウィンドウのサイズを変更すると、 "#image-ul"がブラウザウィンドウの下端よりも上にあるかどうかを変更するときに、データスクロールの速度は変わらないので、私はウェブページを更新する(idとクラス名は正しい)。
ブラウザウィンドウを更新せずに変更するには、データスクロール速度が必要です。誰かが私が間違って行ったことを見ることができますか?
<script>
// Assign attribute specific "data-scroll-speed" to elements upon loading, resizing and scrolling of the webpage page. "if/else" is depending on if #image-ul is fully above the bottom edge of the browser window.
$(document).ready(function() {
$(window).on('load resize scroll', function() {
var WindowScrollTop = $(this).scrollTop(),
Div_one_top = $('#image-ul').offset().top,
Div_one_height = $('#image-ul').outerHeight(true),
Window_height = $(this).outerHeight(true);
if (WindowScrollTop + Window_height >= (Div_one_top + Div_one_height)) {
$('#sloganenglish').attr('data-scroll-speed', '2');
$('.slow-scroll-slider').attr('data-scroll-speed', '5');
$('.slogan-a-line').css('color', 'green');
} else {
$('#sloganenglish').attr('data-scroll-speed', '1');
$('.slow-scroll-slider').attr('data-scroll-speed', '1');
$('.slogan-a-line').css('color', 'red');
}
}).scroll();
});
// data-scroll-speed script
$.fn.moveIt = function() {
var $window = $(window);
var instances = [];
$(this).each(function() {
instances.push(new moveItItem($(this)));
});
window.onscroll = function() {
var scrollTop = $window.scrollTop();
instances.forEach(function(inst) {
inst.update(scrollTop);
});
}
}
var moveItItem = function(el) {
this.el = $(el);
this.speed = parseInt(this.el.attr('data-scroll-speed'));
};
moveItItem.prototype.update = function(scrollTop) {
var pos = scrollTop/this.speed;
this.el.css('transform', 'translateY(' + -pos + 'px)');
};
// Initialization
$(function() {
$('[data-scroll-speed]').moveIt();
});
</script>
誰でも助けてください。 – Eddy