var topBtn = document.getElementById('top');
// 獲取視窗高度
var winHeight = document.documentElement.clientHeight;
window.onscroll = function () {
// 獲取頁(yè)面向上滾動(dòng)距離,chrome瀏覽器識(shí)別document.body.scrollTop,而火狐識(shí)別document.documentElement.scrollTop,這里做了兼容處理
var toTop = document.documentElement.scrollTop || document.body.scrollTop;
// 如果滾動(dòng)超過(guò)一屏,返回頂部按鈕出現(xiàn),反之隱藏
if(toTop>=winHeight){
topBtn.style.display = 'block';
}else {
topBtn.style.display = 'none';
}
}
topBtn.onclick=function () {
var timer = setInterval(function () {
var toTop = document.documentElement.scrollTop || document.body.scrollTop;
// 判斷是否到達(dá)頂部,到達(dá)頂部停止?jié)L動(dòng),沒(méi)到達(dá)頂部繼續(xù)滾動(dòng)
if(toTop == 0){
clearInterval(timer);
}else {
// 設(shè)置滾動(dòng)速度
var speed = Math.ceil(toTop/5);
// 頁(yè)面向上滾動(dòng)
document.documentElement.scrollTop=document.body.scrollTop=toTop-speed;
}
},50);
}
于前端開(kāi)發(fā)人員來(lái)說(shuō),css是我們?cè)偈煜げ贿^(guò)的朋友的,它就相當(dāng)于是我們頁(yè)面的衣服,頁(yè)面好不好看,就看我們css運(yùn)用的是否爐火純青[小鼓掌][小鼓掌][小鼓掌]。css學(xué)起來(lái)簡(jiǎn)單,但是我們要把它“修煉”到出神入化境界,那這可不是一丁點(diǎn)時(shí)間就可以的,需要我們的日積月累,時(shí)刻專(zhuān)研。
而今天,就帶給大家一個(gè)CSS特效-霓虹燈按鈕,這也是我看到很不錯(cuò)的效果,帶來(lái)分享給大家,希望大家喜歡[送心][送心][送心]
效果如下:
最終效果
那好,廢話不多說(shuō),開(kāi)始我們的CSS代碼。
// 這里我們用div標(biāo)簽來(lái)模擬button按鈕,標(biāo)簽可以隨意,a、p、span等都可以
// 通常在開(kāi)發(fā)中使用別的標(biāo)簽來(lái)代替button標(biāo)簽,是因?yàn)樵嫉臉?biāo)簽樣式不好看,
// 我們還得重置樣式,而其他標(biāo)簽不帶有樣式,我們可以更好的控制自己想要的樣式,
// 當(dāng)然,button標(biāo)簽也是可以的,但是如前面所說(shuō),原始的樣式需要我們重置。
<div class="btn">button</div>
body {
margin: 0;
padding: 0;
background: #000; // 黑色背景,只為更能突出樣式效果
}
// 初始化按鈕樣式
.btn {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
width: 200px;
height: 60px;
text-align: center;
line-height: 60px;
color: #fff;
font-size: 24px;
font-family: sans-serif;
text-decoration: none;
text-transform: uppercase;
box-sizing: border-box;
// linear-gradient() 漸變屬性,函數(shù)用于創(chuàng)建一個(gè)表示兩種或多種顏色線性漸變的圖片
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 30px;
}
初始樣式為這樣:
初始樣式
然后我們給按鈕加上動(dòng)畫(huà),代碼如下:
.btn:hover {
// linear: 動(dòng)畫(huà)從開(kāi)始到結(jié)束具有相同的速度。
// infinite: 無(wú)限次播放
animation: animate 8s linear infinite;
}
@keyframes animate {
0% {
background-position: 0%;
}
100% {
background-position: 400%;
}
}
效果就變?yōu)橄旅孢@樣:
最后我們給它加上鼠標(biāo)移上去的效果,代碼如下:
.btn::before {
content: '';
position: absolute;
top: -5px;
left: -5px;
right: -5px;
bottom: -5px;
z-index: -1;
background: linear-gradient(90deg, #03a9f4, #f441a5, #ffeb3b, #03a9f4);
background-size: 400%;
border-radius: 40px;
opacity: 0;
transition: .5s;
}
.btn:hover::before {
filter: blur(20px);
opacity: 1;
animation: animate 8s linear infinite;
}
現(xiàn)在這樣,就是我們的最終效果了:
就此,我們的霓虹燈的按鈕效果就完成了
不足百行,我們就完成了這個(gè)效果,以下是我們的CSS的全部代碼:
。 reload
reload 方法,該方法強(qiáng)迫瀏覽器刷新當(dāng)前頁(yè)面。
語(yǔ)法:location.reload([bForceGet])
參數(shù): bForceGet, 可選參數(shù), 默認(rèn)為 false,從客戶端緩存里取當(dāng)前頁(yè)。true, 則以 GET 方式,從服務(wù)端取最新的頁(yè)面, 相當(dāng)于客戶端點(diǎn)擊 F5("刷新")
reload() 方法用于重新加載當(dāng)前文檔。
如果該方法沒(méi)有規(guī)定參數(shù),或者參數(shù)是 false,它就會(huì)用 HTTP 頭 If-Modified-Since 來(lái)檢測(cè)服務(wù)器上的文檔是否已改變。如果文檔已改變,reload() 會(huì)再次下載該文檔。如果文檔未改變,則該方法將從緩存中裝載文檔。這與用戶單擊瀏覽器的刷新按鈕的效果是完全一樣的。
2.
2,replace 方法,該方法通過(guò)指定URL替換當(dāng)前緩存在歷史里(客戶端)的項(xiàng)目,因此當(dāng)使用replace方法之后,你不能通過(guò)“前進(jìn)”和“后退”來(lái)訪問(wèn)已經(jīng)被替換的URL。
語(yǔ)法: location.replace(URL)
通常使用: location.reload() 或者是 history.go(0) 來(lái)做。
此方法類(lèi)似客戶端點(diǎn)F5刷新頁(yè)面,所以頁(yè)面method="post"時(shí),會(huì)出現(xiàn)"網(wǎng)頁(yè)過(guò)期"的提示。
因?yàn)镾ession的安全保護(hù)機(jī)制。
當(dāng)調(diào)用 location.reload() 方法時(shí), aspx頁(yè)面此時(shí)在服務(wù)端內(nèi)存里已經(jīng)存在, 因此必定是 IsPostback 的。
如果有這種應(yīng)用: 需要重新加載該頁(yè)面,也就是說(shuō)期望頁(yè)面能夠在服務(wù)端重新被創(chuàng)建,期望是 Not IsPostback 的。
這里,location.replace() 就可以完成此任務(wù)。被replace的頁(yè)面每次都在服務(wù)端重新生成。
代碼: location.replace(location.href);
返回并刷新頁(yè)面:
location.replace(document.referrer);
document.referrer //前一個(gè)頁(yè)面的URL
不要用 history.go(-1),或 history.back();來(lái)返回并刷新頁(yè)面,這兩種方法不會(huì)刷新頁(yè)面。
附:
Javascript刷新頁(yè)面的幾種方法:
復(fù)制代碼 代碼如下:
1,history.go(0)
2,location.reload()
3,location=location
4,location.assign(location)
5,document.execCommand('Refresh')
6,window.navigate(location)
7,location.replace(location)
8,document.URL=location.href
自動(dòng)刷新頁(yè)面的方法:
1,頁(yè)面自動(dòng)刷新:把如下代碼加入<head>區(qū)域中
復(fù)制代碼 代碼如下:
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次頁(yè)面.
2,頁(yè)面自動(dòng)跳轉(zhuǎn):把如下代碼加入<head>區(qū)域中
復(fù)制代碼 代碼如下:
<meta http-equiv="refresh" content="20;url=http://www.jb51.net">
其中20指隔20秒后跳轉(zhuǎn)到http://www.jb51.net頁(yè)面
3,頁(yè)面自動(dòng)刷新js版
復(fù)制代碼 代碼如下:
<script language="JavaScript">
function myrefresh()
{
window.location.reload();
}
setTimeout('myrefresh()',1000); //指定1秒刷新一次
</script>
4,JS刷新框架的腳本語(yǔ)句
復(fù)制代碼 代碼如下:
//刷新包含該框架的頁(yè)面用
<script language=JavaScript>
parent.location.reload();
</script>
//子窗口刷新父窗口
<script language=JavaScript>
self.opener.location.reload();
</script>
( 或 <a href="javascript:opener.location.reload()">刷新</a> )
//刷新另一個(gè)框架的頁(yè)面用
<script language=JavaScript>
parent.另一FrameID.location.reload();
</script>
如果想關(guān)閉窗口時(shí)刷新或想開(kāi)窗時(shí)刷新,在<body>中調(diào)用以下語(yǔ)句即可。
復(fù)制代碼 代碼如下:
<body onload="opener.location.reload()"> 開(kāi)窗時(shí)刷新
<body onUnload="opener.location.reload()"> 關(guān)閉時(shí)刷新
<script language="javascript">
window.opener.document.location.reload()
</script>
一、先來(lái)看一個(gè)簡(jiǎn)單的例子:
下面以三個(gè)頁(yè)面分別命名為frame.html、top.html、bottom.html為例來(lái)具體說(shuō)明如何做。
frame.html 由上(top.html)下(bottom.html)兩個(gè)頁(yè)面組成,代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> frame </TITLE>
</HEAD>
<frameset rows="50%,50%">
<frame name=top src="top.html">
<frame name=bottom src="bottom.html">
</frameset>
</HTML>
現(xiàn)在假設(shè)top.html (即上面的頁(yè)面) 有七個(gè)button來(lái)實(shí)現(xiàn)對(duì)bottom.html (即下面的頁(yè)面) 的刷新,可以用以下七種語(yǔ)句,哪個(gè)好用自己看著辦了。
top.html 頁(yè)面的代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> top.html </TITLE>
</HEAD>
<BODY>
<input type=button value="刷新1" onclick="window.parent.frames[1].location.reload()"><br>
<input type=button value="刷新2" onclick="window.parent.frames.bottom.location.reload()"><br>
<input type=button value="刷新3" onclick="window.parent.frames['bottom'].location.reload()"><br>
<input type=button value="刷新4" onclick="window.parent.frames.item(1).location.reload()"><br>
<input type=button value="刷新5" onclick="window.parent.frames.item('bottom').location.reload()"><br>
<input type=button value="刷新6" onclick="window.parent.bottom.location.reload()"><br>
<input type=button value="刷新7" onclick="window.parent['bottom'].location.reload()"><br>
</BODY>
</HTML>
下面是bottom.html頁(yè)面源代碼,為了證明下方頁(yè)面的確被刷新了,在裝載完頁(yè)面彈出一個(gè)對(duì)話框。
復(fù)制代碼 代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> bottom.html </TITLE>
</HEAD>
<BODY onload="alert('我被加載了!')">
<h1>This is the content in bottom.html.</h1>
</BODY>
</HTML>
解釋一下:
復(fù)制代碼 代碼如下:
1.window指代的是當(dāng)前頁(yè)面,例如對(duì)于此例它指的是top.html頁(yè)面。
2.parent指的是當(dāng)前頁(yè)面的父頁(yè)面,也就是包含它的框架頁(yè)面。例如對(duì)于此例它指的是framedemo.html。
3.frames是window對(duì)象,是一個(gè)數(shù)組。代表著該框架內(nèi)所有子頁(yè)面。
4.item是方法。返回?cái)?shù)組里面的元素。
5.如果子頁(yè)面也是個(gè)框架頁(yè)面,里面還是其它的子頁(yè)面,那么上面的有些方法可能不行。
附:
Javascript刷新頁(yè)面的幾種方法:
1 history.go(0)
2 location.reload()
3 location=location
4 location.assign(location)
5 document.execCommand('Refresh')
6 window.navigate(location)
7 location.replace(location)
8 document.URL=location.href
二、自動(dòng)刷新頁(yè)面
1.頁(yè)面自動(dòng)刷新:把如下代碼加入<head>區(qū)域中
<meta http-equiv="refresh" content="20">
其中20指每隔20秒刷新一次頁(yè)面.
2.頁(yè)面自動(dòng)跳轉(zhuǎn):把如下代碼加入<head>區(qū)域中
<meta http-equiv="refresh" content="20;url=http://www.jb51.net">
其中20指隔20秒后跳轉(zhuǎn)到http://www.jb51.net頁(yè)面
3.頁(yè)面自動(dòng)刷新js版
[Ctrl+A 全選 注:如需引入外部Js需刷新才能執(zhí)行]
三、java在寫(xiě)Servler,Action等程序時(shí),要操作返回頁(yè)面的話(如談出了窗口,操作完成以后,關(guān)閉當(dāng)前頁(yè)面,刷新父頁(yè)面)
復(fù)制代碼 代碼如下:
1 PrintWriter out = response.getWriter();
2 out.write("<script type=\"text/javascript\">");
3 ////子窗口刷新父窗口
4 out.write("self.opener.location.reload();");
5 //關(guān)閉窗口
6 out.write("window.opener=null;");
7 out.write("window.close();");
8 out.write("</script>");
四、JS刷新框架的腳本語(yǔ)句
1.如何刷新包含該框架的頁(yè)面用
復(fù)制代碼 代碼如下:
<script language=JavaScript>
parent.location.reload();
</script>
*請(qǐng)認(rèn)真填寫(xiě)需求信息,我們會(huì)在24小時(shí)內(nèi)與您取得聯(lián)系。