dongtu0363 2014-02-24 12:59
浏览 30
已采纳

Wordpress 3.8:jQuery无法正常工作 - 没有错误

OK,

so I've got this weird situation. I'm trying to include Paul Underwood's simple smooth scroll script (http://www.paulund.co.uk/smooth-scroll-to-internal-links-with-jquery) in a Wordpress one-pager running on Wordpress 3.8.1. However, the smooth scroll ain't working.

The script works perfectly on JFiddle, I've checked it for errors, but it's a simple copy-paste from the source, so that shouldn't be the problem. I'm pretty sure I've enqueued it properly in functions.php (yes, I also registerd jQuery). And it should work in noConflict.

So what am I missing here? It won't surprise me if it's a stupid little mistake...

Anyway, thanks in advance everyone :)

The HTML:

<a href="#main"><img class="arrow" src="<?php bloginfo('stylesheet_directory'); ?>/images/arrow-down.png" alt="scroll down"></a>

The script:

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' );
  • 写回答

3条回答 默认 最新

  • dsgfdgh14569 2014-03-05 15:28
    关注

    OK, so I figured it out, guys.

    As I predicted, it was some stupid little thing.

    There was a relic

    body{overflow-x: hidden} 
    

    in my stylesheet.

    This is what's been trolling me - removed the line, and now everything works fine.

    Thanks for the help, though :-)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧