首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义PHP和CSS不能作为Wordpress插件使用-光标

自定义PHP和CSS不能作为Wordpress插件使用-光标
EN

Stack Overflow用户
提问于 2020-07-19 08:08:24
回答 1查看 53关注 0票数 0

我正在尝试让一个自定义光标在我的Wordpress网站上工作。我让它与微软的Visual Studio Code在实时服务器上脱机工作,但不是在Wordpress上。我在这个插件中使用了两个文件: cursor.php和cursor.css。我正在使用FileZilla上传这些文件到wordpress插件文件夹,并通过可湿性粉剂管理面板激活插件。

我的第一个文件(cursor.php)

代码语言:javascript
复制
<?php

/**
Plugin Name:    Labrador Cursor
Version:        1.2
Author:         Labrador
License:        N/A
*/

add_action( 'wp_head', 'cool_cursor' );

function cool_cursor(){
    ?>  
    <style>
    <?php include 'cursor.css'; ?>
    </style>
    
    <script type="text/javascript">

    let mouseCursor =document.querySelector('.cursor');
      
    const cursor = document.querySelector(".cursor");
    document.addEventListener('mousemove', e => {
        cursor.style.top = e.pageY + 'px';
        cursor.style.left = e.pageX + 'px';
        })

    document.addEventListener('click', () => {
        cursor.classList.add("expand");
        setTimeout(() => {
            cursor.classList.remove("expand");
            }, 500);
    })

    </script>
    <?php
}
?>

我的第二个文件(cursor.css)

代码语言:javascript
复制
body {
  margin: 0;
  height: 100vh;
}

.cursor {
  width: 20px;
  height: 20px;
  border: 1.5px solid #0170b4;
  border-radius: 50%;
  position: absolute;
  pointer-events: none;
  -webkit-transition-duration: 200ms;
  transition-duration: 200ms;
  -webkit-transition-timing-function: ease-out;
  transition-timing-function: ease-out;
  -webkit-animation: cursorAnim .5s infinite alternate;
  animation: cursorAnim .5s infinite alternate;
}

.cursor::after {
  content: "";
  width: 0px;
  height: 0px;
  position: absolute;
  border: 2px solid black;
  border-radius: 50%;
  top: 8px;
  left: 8px;
  -webkit-transition: none;
  transition: none;
  -webkit-animation: none;
          animation: none;
}

.expand {
  -webkit-animation: cursorAnim2 0.5s forwards;
          animation: cursorAnim2 0.5s forwards;
  border: 2px solid #00b7ff;
}

@-webkit-keyframes cursorAnim {
  from {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  to {
    -webkit-transform: scale(0.75);
            transform: scale(0.75);
  }
}

@keyframes cursorAnim {
  from {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  to {
    -webkit-transform: scale(0.75);
            transform: scale(0.75);
  }
}

@-webkit-keyframes cursorAnim2 {
  0% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  50% {
    -webkit-transform: scale(2);
            transform: scale(2);
  }
  100% {
    -webkit-transform: scale(1);
            transform: scale(1);
    opacity: 0;
  }
}

@keyframes cursorAnim2 {
  0% {
    -webkit-transform: scale(1);
            transform: scale(1);
  }
  50% {
    -webkit-transform: scale(2);
            transform: scale(2);
  }
  100% {
    -webkit-transform: scale(1);
            transform: scale(1);
    opacity: 0;
  }
}
/*# sourceMappingURL=cursormain.css.map */

有没有人知道我是不是错过了什么?

致以敬意,

拉布拉多犬

EN

回答 1

Stack Overflow用户

发布于 2020-07-19 10:34:02

你遗漏了一个重要的问题--要包含css和js,你应该使用build in wp_register_script函数。完整的规范在这里:

https://developer.wordpress.org/reference/functions/wp_register_script/

关键问题是使用正确的文件路径-这可能是您失败的原因:

代码语言:javascript
复制
wp_register_script ( 'cool_cursor', plugins_url ( 'js/cool_cursor.js', __FILE__ ) );

还有--通常你会将action添加到'init‘--而不是'wp-head’

代码语言:javascript
复制
add_action('init', 'cool_cursor');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62974959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档