网站实用特效-javascript

第一款:

网站焦点监控

<script>
var OriginTitile = document.title,
titleTime;
document.addEventListener("visibilitychange",
function() {
if (document.hidden) {
$;
document.title = "哼 讨厌 你怎么走了吖 o_O!";
clearTimeout(titleTime)
} else {
$;
document.title = "呀呀呀 回来了!" + OriginTitile;
titleTime = setTimeout(function() {
document.title = OriginTitile
},
2000)
}
});
</script>

另外一种

<script>
var originalTitle = document.title;
window.onblur = function(){document.title = '要玩捉迷藏吗'};
window.onfocus = function(){document.title = originalTitle};
</script>

第二款:

闪烁字体

在适当位置添加<p id=”binft”></p>
引入 JavaScript

<script>
var binft = function (r) {
function t() {
return b[Math.floor(Math.random() * b.length)]
}

function e() {
return String.fromCharCode(94 * Math.random() + 33)
}

function n(r) {
for (var n = document.createDocumentFragment(), i = 0; r > i; i++) {
var l = document.createElement("span");
l.textContent = e(), l.style.color = t(), n.appendChild(l)
}
return n
}

function i() {
var t = o[c.skillI];
c.step ? c.step-- : (c.step = g, c.prefixP < l.length ? (c.prefixP >= 0 && (c.text += l[c.prefixP]), c.prefixP++) : "forward" === c.direction ? c.skillP < t.length ? (c.text += t[c.skillP], c.skillP++) : c.delay ? c.delay-- : (c.direction = "backward", c.delay = a) : c.skillP > 0 ? (c.text = c.text.slice(0, -1), c.skillP--) : (c.skillI = (c.skillI + 1) % o.length, c.direction = "forward")), r.textContent = c.text, r.appendChild(n(c.prefixP < l.length ? Math.min(s, s + c.prefixP) : Math.min(s, t.length - c.skillP))), setTimeout(i, d)
}
var l = "",
o = ["无论蓬户荆扉", "都将因你的倚闾", "而成为我的凯旋门", "生活琐碎", "三两烈酒"].map(function (r) {
return r + "."
}),
a = 2,
g = 1,
s = 5,
d = 75,
b = ["rgb(110,64,170)", "rgb(150,61,179)", "rgb(191,60,175)", "rgb(228,65,157)", "rgb(254,75,131)", "rgb(255,94,99)", "rgb(255,120,71)", "rgb(251,150,51)", "rgb(226,183,47)", "rgb(198,214,60)", "rgb(175,240,91)", "rgb(127,246,88)", "rgb(82,246,103)", "rgb(48,239,130)", "rgb(29,223,163)", "rgb(26,199,194)", "rgb(35,171,216)", "rgb(54,140,225)", "rgb(76,110,219)", "rgb(96,84,200)"],
c = {
text: "",
prefixP: -s,
skillI: 0,
skillP: 0,
direction: "forward",
delay: a,
step: g
};
i()
};
binft(document.getElementById('binft'));
</script>

第三款:

网站运营时间

第一种

<code class="lang-JavaScript hljs"><p>已苟活世界 <b> <span class="xml"><span class="hljs-tag"><<span class="hljs-name">strong</span>></span> <span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">language</span>=<span class="hljs-string">"JavaScript"</span> <span class="hljs-attr">type</span> =<span class="hljs-string">"text/javascript"</span>></span><span class="javascript"> <span class="hljs-keyword">var</span> urodz = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(<span class="hljs-string">"12/07/2017"</span>); <span class="hljs-keyword">var</span> now = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Date</span>(); <span class="hljs-keyword">var</span> ile = now.getTime() - urodz.getTime(); <span class="hljs-keyword">var</span> dni = <span class="hljs-built_in">Math</span>.floor(ile / (<span class="hljs-number">1000</span> * <span class="hljs-number">60</span> * <span class="hljs-number">60</span> * <span class="hljs-number">24</span>)); <span class="hljs-built_in">document</span>.write( + dni) </span><span class="hljs-tag"></<span class="hljs-name">script</span>></span> <span class="hljs-tag"></<span class="hljs-name">strong</span>></span></span> <<span class="hljs-regexp">/b> 天</</span>p></code></pre><p> </p>

第二种为 (像时钟一样走动)
合适位置添加

<span>博客已运行</span><span id=bin_tm></span>

引入 JavaScript

<script type="text/javascript">
function show_date_time(){window.setTimeout("show_date_time()",1e3);var BirthDay=new Date("2016/06/06 00:00:00"),today=new Date,timeold=today.getTime()-BirthDay.getTime(),msPerDay=864e5,e_daysold=timeold/msPerDay,daysold=Math.floor(e_daysold),e_hrsold=24*(e_daysold-daysold),hrsold=Math.floor(e_hrsold),e_minsold=60*(e_hrsold-hrsold),minsold=Math.floor(60*(e_hrsold-hrsold)),seconds=Math.floor(60*(e_minsold-minsold));bin_tm.innerHTML=daysold+"天"+hrsold+"小时"+minsold+"分"+seconds+"秒";}
show_date_time();</script>

第四款:

标题打字特效
<!–标题打字特效引入–>
<p id =“typetitle”>可能我在也不会遇到第二这样的她</p>

<script>
var typingbefore = document.getElementById("typetitle").innerText;//获取标题内容
document.getElementById('typetitle').innerText = "";//将标题内容赋值为空
var i = 0;
function typetitle(){
var typingafter = document.getElementById('typetitle');//获取标题元素
if(i <= typingbefore.length){
typingafter.innerHTML = typingbefore.slice(0,i++)+'|';//将标题内容通过slice()方法返回
setTimeout('typetitle()',100);//每100毫秒执行一次
}else{
typingafter.innerHTML = typingbefore;//当标题内容全部返回后,去掉最后的‘|’
}
}
typetitle();
</script>

转自Bin’blog

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享
抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片