简体   繁体   English

想要在每个wordpress网站页面的wordpress插件中运行jQuery代码

[英]Want to run jQuery code in wordpress plugin on every wordpress site page

I am trying to make a wordpress plugin that will run a jQuery script when I activate plugin and my jquery code is below: 我正在尝试制作一个wordpress插件,当我激活该插件并且我的jquery代码如下时,它将运行jQuery脚本:

jQuery(document).ready(function($){

    jQuery(window).scroll(function() {

    if(jQuery(this).scrollTop() != 0) {
        jQuery("#toTop").fadeIn("slow");    
    } else {
        jQuery("#toTop").fadeOut("slow");
    }
});

jQuery("#toTop").click(function() {
    jQuery("body,html").animate({scrollTop:0},1000);
});


});

Please tell me wordpress plugin code which will run this query on every wordpress site page when I activate plugin. 请告诉我wordpress插件代码,当我激活插件时,它将在每个wordpress网站页面上运行此查询。

to insert js into the footer of every page, try; 将js插入每个页面的页脚,请尝试;

<?php
function myJScript(){
// echo js here, or output it like below..
?>
<script>
jQuery(document).ready(function($){

    jQuery(window).scroll(function() {

    if(jQuery(this).scrollTop() != 0) {
        jQuery("#toTop").fadeIn("slow");    
    } else {
        jQuery("#toTop").fadeOut("slow");
    }
  });

  jQuery("#toTop").click(function() {
    jQuery("body,html").animate({scrollTop:0},1000);
  });
});
</script>
<?php
} // end function

// call function myJScript in the footer of every page
add_action('wp_footer', 'myJScript'); 

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

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