【发布时间】:2014-11-21 20:13:01
【问题描述】:
如果您能帮助我解决此问题,我将非常感谢您。
我正在尝试在 WordPress 的某个页面上加载外部 jQuery 脚本。 该页面的标题是program。 jQuery文件标题也是program.js
这是我在functions.php中添加的内容
function my_scripts_method() {
wp_register_script('program', get_template_directory_uri() . '/js/program.js');
if(is_page( program )){
wp_enqueue_script('program');
}
}
add_action('wp_enqueue_scripts', 'my_scripts_method');
这仅在页面程序上加载脚本,到目前为止这是有效的,但是脚本没有运行,它不工作。
这是我的 program.js 文件
var $root = $('html, body');
$('a').click(function() {
var href = $.attr(this, 'href');
$root.animate({
scrollTop: $(href).offset().top
}, 500, function () {
window.location.hash = href;
});
return false;
});
$(function() {
var $sidebar = $("#sidebar-wrapper"),
$window = $(window),
offset = $sidebar.offset(),
topPadding = 15;
$window.scroll(function() {
if ($window.scrollTop() > offset.top) {
$sidebar.stop().animate({
marginTop: $window.scrollTop() - offset.top + topPadding
}, 400);
} else {
$sidebar.stop().animate({
marginTop: 0
}, 400);
}
});
});
感谢您的帮助,我似乎真的无法让它工作。
【问题讨论】:
标签: javascript php jquery wordpress