我正在使用我的wordpress網站,並且使用靜態頁面作爲我的主頁/主頁。我想使用視差滾動,但我不能讓我的腳本加載和工作。我的腳本在wordpress靜態網站中不工作
我聯繫它頭部像這樣:
<script type="text/javascript" src="<?php bloginfo('template_url'); ?>/js/scroll.js"></script>
,這是我的滾動腳本:
(function($) {
$.fn.parallax = function(options) {
var windowHeight = $(window).height();
// Establish default settings
var settings = $.extend({
speed: 0.15
}, options);
// Iterate over each object in collection
return this.each(function() {
// Save a reference to the element
var $this = $(this);
// Set up Scroll Handler
$(document).scroll(function(){
var scrollTop = $(window).scrollTop();
var offset = $this.offset().top;
var height = $this.outerHeight();
// Check if above or below viewport
if (offset + height <= scrollTop || offset >= scrollTop + windowHeight) {
return;
}
var yBgPosition = Math.round((offset - scrollTop) * settings.speed);
// Apply the Y Background Position to Set the Parallax Effect
$this.css('background-position', 'center ' + yBgPosition + 'px');
});
});
}
}(jQuery));
$('.parallax-section-1').parallax({
speed : 0.15
});
我發現了一些文章,我將不得不使用的functions.php和enque的腳本,但我從來沒有這樣做過,所以我有點失落,所以任何幫助將不勝感激。
我做了這一切,當我查看源代碼和搜索滾動。js它沒有找到任何東西 – mheonyae
好吧,我發現我有一個錯誤,導致你的方法不工作。感謝您的幫助,現在就開始工作。 – mheonyae