javascript - 如何将 Scrollify.js 与 Wordpress 和 Elementor 一起使用?

标签 javascript jquery wordpress elementor jquery-scrollify

我对网络开发和编程完全陌生,我想在我的 WP 网站上使用 Scrollify。

所以我只想在一个页面中加载 Scrollify,所以我将它添加到 functions.php

function load_js_assets() {
if( is_page( 26 ) ) {
    wp_enqueue_script('scrollify', 'https://goodlifesoft.com/scrollify.js', array('jquery'), '', false);
} 

我在控制台中添加了一条消息,以查看文件已加载。

我在 header.php

加载了最新版本的 jquery
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

我在footer.php中调用了Scrollify函数

<script>
    $(function() {
      $.scrollify({
        section : ".elementor-element.elementor-element.elementor-section-height-full.elementor-section-content-middle.elementor-section-boxed.elementor-section-height-default.elementor-section-items-middle.elementor-section.elementor-top-section",
      });
    });
  </script>

这是我在控制台中收到的消息。 来自控制台的内容

enter image description here

这在 JSfiddle 中对我有用 https://jsfiddle.net/Balodis/w697stj5/60/

如果有人能指出我做错了什么,我将不胜感激。

谢谢!

最佳答案

尝试在我的网站上实现类似的东西并让它工作时发现了这个线程 - 这是我所做的:

  1. 我下载了 scrollify.js 脚本并将其上传到我的 wordpress 子主题文件。

  2. 我使用子函数调用脚本.php

add_action('wp_enqueue_scripts', 'scroll_script');

function scroll_script() {
    wp_enqueue_script(
        'custom-script',
        get_stylesheet_directory_uri().
        '/jquery.scrollify.js',
        array('jquery')
    );
}
  1. 最后,我将此代码添加到页脚
<script>
    jQuery(function() {
      jQuery.scrollify({
        section : ".panel",
        sectionName : "data-id",

        interstitialSection : "",
        easing: "easeOutExpo",
        scrollSpeed: 1100,
        offset : 0,
        scrollbars: true,
        standardScrollElements: "",
        setHeights: true,
        overflowScroll: true,
        updateHash: true,
        touchScroll:true,
        before:function() {},
        after:function() {},
        afterResize:function() {},
        afterRender:function() {}
      });
});
</script>

当然,您必须将“Section”类编辑为您想要在自己的页面/布局中滚动的元素。

关于javascript - 如何将 Scrollify.js 与 Wordpress 和 Elementor 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54933229/

相关文章:

javascript - 使用 KnockoutJs 映射插件进行递归模板化

c# - 当在内容上方包含 javascript 时,HTML 页面消失

php - woocommerce remove_action 不起作用但添加

javascript - 将图像居中并缩放高度/宽度以适合 flexbox 父级?

javascript - backbone.js:将属性设置为现有值时触发的模型事件?

jQuery 1.4.1 和 Firefox 16.0.1 奇怪的属性问题

jQuery:$.append 和 $.html 不起作用

WordPress 分页不起作用 - 始终显示第一页内容

php - 在 Wordpress 中运行 MySQL 查询会导致 HTML 标记消失?

javascript - 为什么一个元素在从 DOM 中移除后仍然可以访问?