gpt4 book ai didi

javascript - 视差 H1 和 H2

转载 作者:太空宇宙 更新时间:2023-11-03 18:34:30 25 4
gpt4 key购买 nike

有人能告诉我如何调整这个 .js 吗?我希望它能够在我的 html 中使用 ID 应用于 H1 和 H2。现在它只适用于 css 背景图像。下面是我正在使用的 .js。我是 JavaScript 的初学者;)

希望大家能帮帮我!

    (function( $ ){
var $window = $(window);
var windowHeight = $window.height();

$window.resize(function () {
windowHeight = $window.height();
});

$.fn.parallax = function(xpos, speedFactor, outerHeight) {
var $this = $(this);
var getHeight;
var firstTop;
var paddingTop = 0;

//get the starting position of each element to have parallax applied to it
$this.each(function(){
firstTop = $this.offset().top;
});

if (outerHeight) {
getHeight = function(jqo) {
return jqo.outerHeight(true);
};
} else {
getHeight = function(jqo) {
return jqo.height();
};
}

// setup defaults if arguments aren't specified
if (arguments.length < 1 || xpos === null) xpos = "50%";
if (arguments.length < 2 || speedFactor === null) speedFactor = 0.1;
if (arguments.length < 3 || outerHeight === null) outerHeight = true;

// function to be called whenever the window is scrolled or resized
function update(){
var pos = $window.scrollTop();

$this.each(function(){
var $element = $(this);
var top = $element.offset().top;
var height = getHeight($element);

// Check if totally above or totally below viewport
if (top + height < pos || top > pos + windowHeight) {
return;
}

$this.css('backgroundPosition', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px");

});
}

$window.bind('scroll', update).resize(update);
update();
};
})(jQuery);

最佳答案

应该是background-position。你可以尝试改变吗?

$this.css('background-position', xpos + " " + Math.round((firstTop - pos) * speedFactor) + "px");

关于javascript - 视差 H1 和 H2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19068635/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com