简体   繁体   English

基本的视差无法使用stellar.js

[英]Basic parallax not working using stellar.js

I've spent the past couple hours trying to solve what should be a really simple solution, but I'm banging my head against the wall and hoping someone here can spot what I'm missing. 在过去的几个小时中,我一直在尝试解决应该是一个非常简单的解决方案,但是我正把头撞在墙上,希望这里的人可以发现我所缺少的。

Trying to make a featured image slider have a parallax effect to it (similar to this ). 试图让一个有特色的图像滑块有它的视差效果(类似这样 )。 I've called the stellar script in my header as follows: 我在标头中调用了恒星脚本,如下所示:

<script src="<?php echo get_stylesheet_directory_uri(); ?>/javascripts/jquery.stellar.min.js"></script>
<script>
$(function() {
    $.stellar();
});
</script>

This is the image slider that I want to scroll slower than the rest of the page (I'm using a custom fields plugin... that's what you'll see being called there): 这是我要比页面其余部分滚动慢的图像滑块(我正在使用自定义字段插件...这就是在那里看到的名称):

<div class="featured-slider parallax" data-stellar-background-ratio="0.5"><?php the_field('featured_slider'); ?></div>

And here's the only CSS I've added to the element: 这是我添加到元素中的唯一CSS:

.parallax {
    position: relative;
}

Is there something more I should be doing? 还有什么我应该做的吗? Am I missing something obvious? 我是否缺少明显的东西?

Here's the page where I'm trying to do this. 这是我要执行此操作的页面。

It looks like on your page you are adding the script tag for stellar before jquery. 看起来在您的页面上,您在jquery之前添加了star的脚本标签。 You need the order to be Jquery, stellar, then your special script. 您需要的命令是Jquery,stellar,然后是您的特殊脚本。 Everything else you are doing looks correct. 您正在执行的其他所有操作看起来都是正确的。

//script tag for jquery
//script tag for stellar
//your script with stellar stuff. 

Also Wordpress sometimes does not like the $ . 此外,Wordpress有时不喜欢$ Use jQuery instead to initialize stellar and document ready. 改用jQuery初始化恒星并准备好文档。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM