提问人:HectorACampo NYC 提问时间:8/28/2023 最后编辑:p7dxbHectorACampo NYC 更新时间:8/28/2023 访问量:29
我的 javascript 在 Safari 上运行,但不能在 Chrome 上运行
My javascript is working on Safari but not Chrome
问:
我将附上下面的代码,但您也可以在 hectorcampoblog.com 查看页面源代码并实时查看浏览器不兼容。我知道 javascript 因浏览器不兼容而臭名昭著,但有没有人对这个新手自学成才的编码员有任何建议,以使我免于将来的头痛?比如,是否有应用程序可以检查这一点?或者也许是一个教授所有常见错误的论坛?我在这里抓着稻草。
window.addEventListener('scroll', reveal);{
function reveal (){
let reveals = document.querySelectorAll('.reveal');
for(let i = 0; i < reveals.length; i++){
/*
*i stands for iteration is the repetition of a process in a computer program, usually done with the help of loops.
*Instead of variable = variable + 1; You can type variable += 1; Or varibale++;
*You can also use -= , *= , /= , or instead of ++ use --
*/
let windowHeight = window.innerHeight;
let revealTop = reveals[i].getBoundingClientRect().top;
/*The Element.getBoundingClientRect() method returns a DOMRect object providing information about the size of an element and its position relative to the viewport*/
let revealPoint = 150;
if (revealTop < windowHeight - revealPoint){
reveals[i].classList.add('active');
}
else {
reveals[i].classList.remove('active');
/*
*As you scroll it adds 'active' to the end of any div CLASS ending in 'reveal' or removes 'active' as you scroll past
*You can now style the class with active and the class without active
*/`your text`
我的猜测是存在语法问题,阻止将“active”添加到“reveal”类中。我在两个“active”前面都添加了一个“.”,删除了“reveal”前面的“.”,将 revealPoint 更改为 0,并将 innerHeight 更改为 Height,但没有运气。
答: 暂无答案
评论