CSS / Javascript - fadeIn 效果在 Safari 上不起作用

2024-01-13

我正在将一个前端站点加载到 Wordpress 上,并加载了一些 javascript 文件,其中之一用于主页上各部分的淡入效果。它在 Firefox 和 Chrome 上运行良好,但在 Safari 中不起作用,我不知道为什么。基本上,opacity: 0;Safari 中遵循该规则,因此当我向下滚动时,我只会看到底部带有页脚的空白页面。

浏览器中没有任何真正的标记,所以我有点卡住了。

这是代码 -

淡入.js

jQuery(document).on("scroll", function () {
  var pageTop = jQuery(document).scrollTop()
  var pageBottom = pageTop + jQuery(window).height()
  var tags = jQuery("section")

  for (var i = 0; i < tags.length; i++) {
    var tag = tags[i]

    if (jQuery(tag).position().top < pageBottom) {
      jQuery(tag).addClass("visible")
    } else {
      jQuery(tag).removeClass("visible")
    }
  }
})

  // Have put jQuery instead of $ due to error flagging up in Wordpress

样式.css

/* Fade in/out */

section {
  opacity: 0;

  transform: translate(0, 10px); 
  transition: all 1s;
}

section.visible { 
  opacity: 1;
  transform: translate(0, 0); 
}


/*  ---------------------- */

函数.php

function html5blankchild_all_scriptsandstyles() {
//Load JS and CSS files in here
  wp_register_script ('jquery', get_stylesheet_directory_uri() . 'https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js');
  wp_register_script ('smooth-scroll', get_stylesheet_directory_uri() . '/js/smooth-scroll.js', array('jquery'));
  wp_register_script ('fadein', get_stylesheet_directory_uri() . '/js/fadein.js', array('jquery'));
  wp_register_script ('ps', get_stylesheet_directory_uri() . '/js/ps.js',true);
  wp_register_style ('font-awesome', 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css');
  wp_register_style ('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css');
  wp_register_style ('normalize', 'https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css');
  wp_register_style ('style', get_stylesheet_directory_uri() . '/style.css');

  wp_enqueue_script('jquery');
  wp_enqueue_script('ps');
  wp_enqueue_style( 'font-awesome');
  wp_enqueue_style( 'bootstrap');
  wp_enqueue_style( 'normalize');
  wp_enqueue_style( 'style');
  if ( is_front_page() ) {
  wp_enqueue_script('fadein');
  }
  if ( is_front_page() ) {
  wp_enqueue_script('smooth-scroll');
  }

}
add_action( 'wp_enqueue_scripts', 'html5blankchild_all_scriptsandstyles' );

更新 -

header.php

<head><!-- head code goes here --><?head> 
<body <?php ?>>

        <header>
        <nav>
            <a href="<?php the_permalink(4); ?>#particle-slider">Home</a>
            <a href="#what">What we do</a>
            <a href="#who">Who we are</a>
            <a href="#partners">Who we work with</a>
            <a href="#contact">Say hello</a>
            <a href="<?php the_permalink(70); ?>">Blog</a>
        </nav>
    </header>

联系方式.php

<?php /* Template Name: contact */ ?>
<!-- contact template -->

        <section id="contact">
            <div class="container-fluid">
                     <div class="secthead"><span style="color: rgb(63,190,150);">&#43;</span><h1>Say hello</h1></div>
                        <div class="row no-gutters">
                            <div id="hello">        
                                <p>If you would like to receive a quote for a design project, chat about the weather or send us some chocolates, please pop an email in our inbox, call us or write
                                us an old fashioned letter on the below contact details</p> 
                            </div>
                        </div>  
            </div>          
        </section>
<!-- contact template -->       

对于 safari 使用 webkit

section {
  opacity: 0;
  -webkit-transform: translate(0, 10px); 
  -webkit-transition: all 1s;
  transform: translate(0, 10px); 
  transition: all 1s;
}

section.visible { 
  opacity: 1;
  -webkit-transform: translate(0, 0); 
  transform: translate(0, 0); 
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CSS / Javascript - fadeIn 效果在 Safari 上不起作用 的相关文章

  • 角度材料在一个表单字段中输入和选择

    I want the input field and the drop down field in the same area like the one on the left I did this on the inspector 无论我
  • React Native 中循环 Json 并显示

    How do I go about looping the result i retrieved from Json render function console log this state list contents
  • Firefox 背景图像在切换标签后消失

    我在渲染背景图像时遇到一些非常奇怪的问题 我不确定这是 Firefox 的错误还是我的错 每次我在 Firefox 中打开项目站点时 所有背景图像都会正确加载并显示 当我切换到另一个选项卡并在一段时间后切换回来后 所有背景图像都消失了 我检
  • 更新 Bootstrap 缩略图网格 - ajax 请求

    设想 我有一个带有显示国家 地区的 Twitter Bootstrap 缩略图网格的视图 当用户单击一张图像时 它应该在同一网格 屏幕 中显示与该国家 地区相关的城市 技术的 首先 我用国家 地区填充 dataProvider 然后我应该将
  • 在网站的一次导航中仅显示一次弹出窗口

    我有一个使用 Laravel 创建的网站 我希望用户第一次访问我的网站时能够看到弹出窗口 我的意思是第一次 用户访问我网站上的任何页面 这是第一次 访问网站上的一些链接页面 现在 这些页面访问不是第一次 在同一选项卡中打开 facebook
  • 不推荐使用 getPreventDefault()。请改用defaultPrevented。为什么我会收到此错误以及解决方案是什么?

    以前我在代码中使用 jQuery 1 7 1 我收到上述错误 然后我直接从谷歌存储库使用了 jQuery 1 11 1 但我仍然收到此错误 我应该如何解决这个问题 由于这个错误 我的其他 jQuery 功能也无法工作 我研究了很多关于该解决
  • 如何在不知道id的情况下从内页获取父iframe元素?

    让我们想象一下我有这样的东西 div div test html 是空页面 自定义hash属性始终具有不同的值 出于安全原因两个页面位于同一域 iframe 元素的数量和顺序是随机的 我的问
  • Bootstrap 的跨浏览器数字微调器/步进器 [关闭]

    Closed 这个问题不符合堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个与 Twitter Bootstrap 2 3 集成的数字微调器 使用 HTML5input type number
  • 用 JavaScript 改变文本颜色?

    我想在单击按钮时更改标题的颜色 这是我的代码 但它不起作用 我不明白为什么不 var about function init about document getElementById about innerHTML about style
  • 为什么我会失去对元素的引用?

    我偶然发现了一些奇怪的东西 至少对我来说 案例如下 我选择一个元素 child1 从 DOM 并将其保存到变量中 我继续添加一个新元素child1的家长 parent1 现在 如果我尝试修改某些值child1它不记录更改 似乎引用已经消失
  • 点击事件的事件处理程序自动触发 - jQuery [重复]

    这个问题在这里已经有答案了 可能的重复 为什么单击事件处理程序会在页面加载后立即触发 https stackoverflow com questions 7102413 why does click event handler fire i
  • React:在哪里扩展对象原型

    我使用创建了一个纯 React 应用程序创建反应应用程序 https github com facebookincubator create react app 我想延长String类并在一个或多个组件中使用它 例如 String prot
  • 纯CSS代码,没有绝对定位

    我试图想出一个纯CSS代码 就像你在电视上看到的那样 仅not粘在屏幕底部 我已经找到了涉及 JS 的东西 但我正在努力避免 JS 我还发现了一些其他人创建的纯 CSS 代码 但这些的问题在于它们都使用position absolute 这
  • React:设置 State 或设置 Prop 而无需重新渲染

    Problem 目前 我有一个LoginForm具有 成功 处理函数的组件handleOnSuccess 然后将其链接到父组件onTokenUpdate由 令牌更新 处理函数定义的属性handleUpdateToken 问题是setStat
  • WordPress - pre_get_posts 代替页面上的 query_posts

    我的情况有点复杂 我会尽量简洁地解释一下 我目前正在使用query posts修改我网站上自定义页面上的主查询 据我所知 它工作得很好 尽管我已经读到 由于多种不同的原因 使用 query posts 是不好的做法 那么 我为什么要使用qu
  • CSS 变换函数顺序

    为什么以下之间的输出存在差异 transform translate 0 100px scale 2 2 and transform scale 2 2 translate 0 100px 第一条语句符合您 我 的期望 将元素向下移动 10
  • 如何对对象数组调用reduce来求和它们的属性?

    说我想求和a x对于中的每个元素arr arr x 1 x 2 x 4 arr reduce function a b return a x b x gt NaN 我有理由相信a x is undefined在某一点 以下工作正常 arr
  • 使用 node-sass 监视整个目录时指定输出文件名

    目前 我可以在查看单个 SCSS 文件时使用 package json 文件中的 node sass build 命令指定文件名 sass build node sass src scss main scss dist css main m
  • 网站可以检测您何时将 Selenium 与 chromedriver 结合使用吗?

    我一直在使用 Chromedriver 测试 Selenium 我注意到有些页面可以检测到您正在使用 Selenium 即使根本没有自动化 即使我只是通过 Selenium 使用 Chrome 手动浏览 Xephyr https en wi
  • localStorage 获取 NULL?

    我不知道为什么 因为我之前已经这样做过并且工作正常 我认为这可能是因为浏览器问题 错误 localStorage setItem foo bar alert localStorage getItem foo 我使用的是 Firefox 3

随机推荐