行,WordPress的3.8:jQuery不工作 - 沒有錯誤
所以我有這種奇怪的情況。我試圖在Wordpress 3.8.1上運行的Wordpress單頁頁面中包含Paul Underwood的簡單平滑滾動腳本(http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery)。 但是,平滑滾動不起作用。
該腳本在JFiddle上完美工作,我檢查了它的錯誤,但它是一個簡單的從源代碼複製粘貼,所以不應該是問題。我很確定我已經在functions.php中正確排列了它(是的,我還註冊了jQuery)。它應該在noConflict中工作。
那麼我在這裏錯過了什麼?如果這是一個愚蠢的小錯誤,不會讓我感到吃驚......
無論如何,在此先感謝大家:)
的HTML:
<a href="#main"><img class="arrow" src="<?php bloginfo('stylesheet_directory'); ?>/images/arrow-down.png" alt="scroll down"></a>
腳本:
jQuery(document).ready(function($) {
$(document).ready(function() {
$('a[href^="#"]').on('click',function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop': $target.offset().top
}, 900, 'swing', function() {
window.location.hash = target;
});
});
});
});
the functions.php
function my_scripts() {
wp_enqueue_script('jquery');
wp_enqueue_style('my-style', get_stylesheet_uri());
wp_register_script('my-script', get_template_directory_uri().'/js/my-script.js', array('jquery'), '1.0', true);
wp_enqueue_script('my-script');
}
add_action('wp_enqueue_scripts', 'my_scripts');
嘿Jai,謝謝你的提示。我嘗試刪除額外的處理程序,但不幸的是,該腳本仍然不工作:( – underscored