欢迎光临
请一秒记住我们的网址:www.xinfangs.com !

WordPress 主题添加鼠标跟随特效

时间煮雨阅读(801)


分享个鼠标跟随特效,给喜欢花花草草的朋友们。这个鼠标跟随特效还是很酷,不是那种鼠标后面跟随一大堆零零碎碎的,仅一个圆圈跟随鼠标指针,当遇到超链接圆圈会变成半透明的背景,国外网站常见的一种的特效,具体效果看本站。

WordPress 主题添加鼠标跟随特效

添加方法非常简单,将下面代码添加到当前主题函数模板 functions.php 最后:

// 加载jquery开始,如果主题已加载不加这段。
function zm_jquery_script() {
	wp_enqueue_script( \'jquery\' );
}
add_action( \'wp_enqueue_scripts\', \'zm_jquery_script\' );
// 加载jquery结束
function zm_mouse_cursor() { ?>
<!-- 必须的DIV -->
<div class=\"mouse-cursor cursor-outer\"></div>
<div class=\"mouse-cursor cursor-inner\"></div>
<!-- JS脚本 -->
<script>
jQuery(document).ready(function($){
	var myCursor = jQuery(\'.mouse-cursor\');
	if (myCursor.length) {
		if ($(\'body\')) {
			const e = document.querySelector(\'.cursor-inner\'),
			t = document.querySelector(\'.cursor-outer\');
			let n,
			i = 0,
			o = !1;
			window.onmousemove = function(s) {
				o || (t.style.transform = \"translate(\" + s.clientX + \"px, \" + s.clientY + \"px)\"),
				e.style.transform = \"translate(\" + s.clientX + \"px, \" + s.clientY + \"px)\",
				n = s.clientY,
				i = s.clientX
			},
			$(\'body\').on(\"mouseenter\", \"a, .cursor-pointer\",
			function() {
				e.classList.add(\'cursor-hover\'),
				t.classList.add(\'cursor-hover\')
			}),
			$(\'body\').on(\"mouseleave\", \"a, .cursor-pointer\",
			function() {
				$(this).is(\"a\") && $(this).closest(\".cursor-pointer\").length || (e.classList.remove(\'cursor-hover\'), t.classList.remove(\'cursor-hover\'))
			}),
			e.style.visibility = \"visible\",
			t.style.visibility = \"visible\"
		}
	}
})

</script>
<!-- 样式 -->
<style>
.mouse-cursor {
	position: fixed;
	left: 0;
	top: 0;
	pointer-events: none;
	border-radius: 50%;
	-webkit-transform: translateZ(0);
	transform: translateZ(0);
	visibility: hidden
}

.cursor-inner {
	margin-left: -3px;
	margin-top: -3px;
	width: 6px;
	height: 6px;
	z-index: 10000001;
	background: #ffa9a4;
	-webkit-transition: width .3s ease-in-out,height .3s ease-in-out,margin .3s ease-in-out,opacity .3s ease-in-out;
	transition: width .3s ease-in-out,height .3s ease-in-out,margin .3s ease-in-out,opacity .3s ease-in-out
}

.cursor-inner.cursor-hover {
	margin-left: -18px;
	margin-top: -18px;
	width: 36px;
	height: 36px;
	background: #ffa9a4;
	opacity: .3
}

.cursor-outer {
	margin-left: -15px;
	margin-top: -15px;
	width: 30px;
	height: 30px;
	border: 2px solid #ffa9a4;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
	z-index: 10000000;
	opacity: .5;
	-webkit-transition: all .08s ease-out;
	transition: all .08s ease-out
}

.cursor-outer.cursor-hover {
	opacity: 0
}

.main-wrapper[data-magic-cursor=hide] .mouse-cursor {
	display: none;
	opacity: 0;
	visibility: hidden;
	position: absolute;
	z-index: -1111
}
</style>
<?php }
add_action( \'wp_footer\', \'zm_mouse_cursor\' );

因默认主题未加载jquery,所以代码中添加了WP自带的jquery,如果你的主题已加载了jquery,则不加第一段的代码(有注释),大部分主题应该都加载了jquery。

当然你也可以将样式添加到当前主题style.css中,包括JS代码也可以加到一个单独文件中加载。

WordPress 主题添加鼠标跟随特效

时间煮雨阅读(784)


2022年第一篇文章,分享个鼠标跟随特效,给喜欢花花草草的朋友们。这个鼠标跟随特效还是很酷,不是那种鼠标后面跟随一大堆零零碎碎的,仅一个圆圈跟随鼠标指针,当遇到超链接圆圈会变成半透明的背景,国外网站常见的一种的特效,具体效果看本站。

添加方法非常简单,将下面代码添加到当前主题函数模板 functions.php 最后:

// 加载jquery开始,如果主题已加载不加这段。
function zm_jquery_script() {
	wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'zm_jquery_script' );
// 加载jquery结束
function zm_mouse_cursor() { ?>
<!-- 必须的DIV -->
<div class="mouse-cursor cursor-outer"></div>
<div class="mouse-cursor cursor-inner"></div>
<!-- JS脚本 -->
<script>
jQuery(document).ready(function($){
	var myCursor = jQuery('.mouse-cursor');
	if (myCursor.length) {
		if ($('body')) {
			const e = document.querySelector('.cursor-inner'),
			t = document.querySelector('.cursor-outer');
			let n,
			i = 0,
			o = !1;
			window.onmousemove = function(s) {
				o || (t.style.transform = "translate(" + s.clientX + "px, " + s.clientY + "px)"),
				e.style.transform = "translate(" + s.clientX + "px, " + s.clientY + "px)",
				n = s.clientY,
				i = s.clientX
			},
			$('body').on("mouseenter", "a, .cursor-pointer",
			function() {
				e.classList.add('cursor-hover'),
				t.classList.add('cursor-hover')
			}),
			$('body').on("mouseleave", "a, .cursor-pointer",
			function() {
				$(this).is("a") && $(this).closest(".cursor-pointer").length || (e.classList.remove('cursor-hover'), t.classList.remove('cursor-hover'))
			}),
			e.style.visibility = "visible",
			t.style.visibility = "visible"
		}
	}
})
 
</script>
<!-- 样式 -->
<style>
.mouse-cursor {
	position: fixed;
	left: 0;
	top: 0;
	pointer-events: none;
	border-radius: 50%;
	-webkit-transform: translateZ(0);
	transform: translateZ(0);
	visibility: hidden
}
 
.cursor-inner {
	margin-left: -3px;
	margin-top: -3px;
	width: 6px;
	height: 6px;
	z-index: 10000001;
	background: #ffa9a4;
	-webkit-transition: width .3s ease-in-out,height .3s ease-in-out,margin .3s ease-in-out,opacity .3s ease-in-out;
	transition: width .3s ease-in-out,height .3s ease-in-out,margin .3s ease-in-out,opacity .3s ease-in-out
}
 
.cursor-inner.cursor-hover {
	margin-left: -18px;
	margin-top: -18px;
	width: 36px;
	height: 36px;
	background: #ffa9a4;
	opacity: .3
}
 
.cursor-outer {
	margin-left: -15px;
	margin-top: -15px;
	width: 30px;
	height: 30px;
	border: 2px solid #ffa9a4;
	-webkit-box-sizing: border-box;
	box-sizing: border-box;
	z-index: 10000000;
	opacity: .5;
	-webkit-transition: all .08s ease-out;
	transition: all .08s ease-out
}
 
.cursor-outer.cursor-hover {
	opacity: 0
}
 
.main-wrapper[data-magic-cursor=hide] .mouse-cursor {
	display: none;
	opacity: 0;
	visibility: hidden;
	position: absolute;
	z-index: -1111
}
</style>
<?php }
add_action( 'wp_footer', 'zm_mouse_cursor' );

因默认主题未加载jquery,所以代码中添加了WP自带的jquery,如果你的主题已加载了jquery,则不加第一段的代码(有注释),大部分主题应该都加载了jquery。

当然你也可以将样式添加到当前主题style.css中,包括JS代码也可以加到一个单独文件中加载。

附:不依赖jquery纯JS版
项目地址:https://github.com/seattleowl/Pointer.js

WordPress显示网站已运行时间

时间煮雨阅读(619)


在网站上显示已运行多少时间是一些站长需要的功能,只需要加一段代码即可实现。代码来自六特网站,本站使用下面第三段。代码贴到footer.php或者右侧html小工具。

1.显示的是运行的 天/小时/分/秒

<span id="timeDate">载入天数...</span><span id="times">载入时分秒...</span><script>// <![CDATA[
var now = new Date(); function createtime(){ var grt= new Date("11/25/2013 21:51:00");//此处修改你的建站时间或者网站上线时间 now.setTime(now.getTime()+250); days = (now - grt ) / 1000 / 60 / 60 / 24; dnum = Math.floor(days); hours = (now - grt ) / 1000 / 60 / 60 - (24 * dnum); hnum = Math.floor(hours); if(String(hnum).length ==1 ){hnum = "0" + hnum;} minutes = (now - grt ) / 1000 /60 - (24 * 60 * dnum) - (60 * hnum); mnum = Math.floor(minutes); if(String(mnum).length ==1 ){mnum = "0" + mnum;} seconds = (now - grt ) / 1000 - (24 * 60 * 60 * dnum) - (60 * 60 * hnum) - (60 * mnum); snum = Math.round(seconds); if(String(snum).length ==1 ){snum = "0" + snum;} document.getElementById("timeDate").innerHTML = "本站已安全运行"+dnum+"天"; document.getElementById("times").innerHTML = hnum + "小时" + mnum + "分" + snum + "秒"; } setInterval("createtime()",250);
// ]]></script>

2.显示的是运行的 天

本站已安全运行了:<span class="smalltxt"><script>// <![CDATA[
BirthDay=new Date("11 25,2013");
today=new Date();
timeold=(today.getTime()-BirthDay.getTime());
sectimeold=timeold/1000
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000
e_daysold=timeold/msPerDay
daysold=Math.floor(e_daysold);
document.write("<font color=red>"+daysold+"</font>天 !");
// ]]></script></span>

3.显示格式:已运行1 年 2 天 3 小时 4 分钟 35 秒

<span id="sitetime"></span><script>// <![CDATA[
function siteTime(){ window.setTimeout("siteTime()", 1000); var seconds = 1000 var minutes = seconds * 60 var hours = minutes * 60 var days = hours * 24 var years = days * 365 var today = new Date() var todayYear = today.getFullYear() var todayMonth = today.getMonth() var todayDate = today.getDate() var todayHour = today.getHours() var todayMinute = today.getMinutes() var todaySecond = today.getSeconds() /* Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳) year - 作为date对象的年份,为4位年份值 month - 0-11之间的整数,做为date对象的月份 day - 1-31之间的整数,做为date对象的天数 hours - 0(午夜24点)-23之间的整数,做为date对象的小时数 minutes - 0-59之间的整数,做为date对象的分钟数 seconds - 0-59之间的整数,做为date对象的秒数 microseconds - 0-999之间的整数,做为date对象的毫秒数 */ var t1 = Date.UTC(2013,11,25,21,30,20) var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond) var diff = t2-t1 var diffYears = Math.floor(diff/years) var diffDays = Math.floor((diff/days)-diffYears*365) var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours) var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes) var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds) document.getElementById("sitetime").innerHTML=" 已运行"+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒" } siteTime()
// ]]></script>
本文引用链接:http://www.66at.com/725.html

WordPress 移除前后台顶部工具栏的指定菜单

时间煮雨阅读(1101)


WordPress 后台顶部工具栏默认有 WP 的 Logo、站名、更新、评论和新建几个菜单,之前云模板分享过如何增加WordPress 后台顶部管理工具栏的自定义菜单,那么再来分享如何移除顶部工具栏的某个菜单。

废话不多,直接上代码:丢在 functions.php 里即可

//移除顶部工具栏
function admin_bar_item ( WP_Admin_Bar $admin_bar ) {
	$admin_bar->remove_menu('wp-logo'); //移动wp的logo
	$admin_bar->remove_menu('site-name'); //移动站点名称
	$admin_bar->remove_menu('updates'); //移动更新提示
	$admin_bar->remove_menu('comments'); //移动评论提示
	$admin_bar->remove_menu('new-content');	//移除新建按钮    
}
add_action( 'admin_bar_menu', 'admin_bar_item', 500 );

纯代码实现wordpress文章阅读次数功能与调用

时间煮雨阅读(544)

核心代码:function.php添加如下代码

function get_post_views ($post_id) {  
   
    $count_key = 'views';  
    $count = get_post_meta($post_id, $count_key, true);  
   
    if ($count == '') {  
        delete_post_meta($post_id, $count_key);  
        add_post_meta($post_id, $count_key, '0');  
        $count = '0';  
    }  
   
    echo number_format_i18n($count);  
   
}  
function set_post_views () {  
   
    global $post;  
   
    $post_id = $post -> ID;  
    $count_key = 'views';  
    $count = get_post_meta($post_id, $count_key, true);  
   
    if (is_single() || is_page()) {  
   
        if ($count == '') {  
            delete_post_meta($post_id, $count_key);  
            add_post_meta($post_id, $count_key, '0');  
        } else {  
            update_post_meta($post_id, $count_key, $count + 1);  
        }  
   
    }  
   
}  
add_action('get_header', 'set_post_views');

调用代码

然后在文章页面single.php的需要显示的位置添加如下代码:

阅读次数 <?php get_post_views($post -> ID); ?>

注意:如果部分博主使用的主题是特殊的主题,那么文章页面应该是loop-single.php,把上面方法里面的single.php替换成loop-single.php即可 

HTML简单的个人引导页

时间煮雨阅读(1350)


之前的网站用的是香港的主机,现在换了一个腾讯国内的服务器,需要备案,以前的网站有太多的内容不容易,备案通过就搜了一个简单的引导页,感觉还是不错的,也可以分享给大家。不多说直接上图,上源码。

请一秒记住我们的网址:www.xinfangs.com !

去投稿去留言