我必须在我的javascript变量中插入px或vh中的值。我需要变量x= 722;变成722px或100vh。
谢谢
var x = 722;
$(window).scroll(function() {
var scroll = $(window).scrollTop();
if (scroll >= x) {
$(".B2a").addClass("AI");
$(".B1a").removeClass("AI");
}
});
发布于 2019-06-10 00:25:36
您的scroll变量已经是一个数字,您不需要添加'px‘
如果需要,你可以在你的函数中使用console.log(scroll);
来调试它!
发布于 2019-06-10 00:40:28
字符串拼接短版本:
var a = 'appels';
var b = 3;
var c = b+' '+a;
alert(c);
a = ' I ate';
c += a;
alert(c);
https://stackoverflow.com/questions/56516276
复制相似问题