xScrollStick 跟隨捲軸漂浮的JS特效

來源:互聯網
上載者:User

這是一個跟隨捲軸漂浮的JS特效,就是說捲軸滾動而元素相對螢幕位置不變

網上有很多類似的效果,本代碼比較起來有如下優點:

1. 相容IE6.0+ & FF1.5+
2. 使用非常簡單,屬於菜鳥最愛的那種拿來就能用的,見下面說明
3. 元素之間不會起衝突,一頁中可以有n個特效,多元素使用無代碼冗餘

缺點有:

1. 只能在聲明為xHTML的文檔中使用
2. 元素最好放在body下
3. 滾動時不可避免的會有閃爍(已經比較輕微,但追求完美者可能覺得不爽)

使用說明:
在頁面中引用JS包,然後在需要特效的div上設定class為xScrollStick即可,當然不要忘記給每個元素寫上你希望它固定的位置

樣本1:
複製代碼 代碼如下:
<div class="xScrollStick" style="left:0px;top:0px">
Content...
</div>

樣本2:
複製代碼 代碼如下:
<div class="xScrollStick positionStyleName">
Content...
</div>

示範:

運行代碼框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <title>xScrollStick Demo</title> <style> .xScrollStick{ position:absolute; padding:15px; border:1px solid black; width:120px; height:24px; } .d1 { left:0px;top:0px; } .d2 { right:0px;top:0px; } .d3 { left:0px;bottom:0px; } .d4 { right:0px;bottom:0px; } </style> </head> <body style="text-align:center;"> 俺是浮動條 俺是浮動條2 俺是浮動條3 俺是浮動條4 afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
頁面由兩個個部分組成:
分頁檔:
代碼拷貝框
複製代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>xScrollStick Demo</title>
<script type="text/javascript" src="sp/js/xscrollstick.js"></script>
<style>
.xScrollStick{
position:absolute;
padding:15px;
border:1px solid black;
width:120px;
height:24px;
}
.d1 { left:0px;top:0px; }
.d2 { right:0px;top:0px; }
.d3 { left:0px;bottom:0px; }
.d4 { right:0px;bottom:0px; }
</style>
</head>
<body style="text-align:center;">
<div class="xScrollStick d1">
<a href="http://www.163.com">俺是浮動條</a>
</div>
<div class="xScrollStick d2">俺是浮動條2</div>
<div class="xScrollStick d3">俺是浮動條3</div>
<div class="xScrollStick d4">俺是浮動條4</div>
<div style="top:0px;width:400px;height:2000px;">
afosdhfosdhg<br>
afosdhfosdhg<br>afosdhfosdhg<br>
afosdhfosdhg<br>afosdhfosdhg<br>
afosdhfosdhg<br>afosdhfosdhg<br>
afosdhfosdhg<br>afosdhfosdhg<br>
afosdhfosdhg<br>afosdhfosdhg<br>
afosdhfosdhg<br>
</div>
</body>
</html>

js:
運行代碼框
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <title>xScrollStick Demo</title> <style> .xScrollStick{ position:absolute; padding:15px; border:1px solid black; width:120px; height:24px; } .d1 { left:0px;top:0px; } .d2 { right:0px;top:0px; } .d3 { left:0px;bottom:0px; } .d4 { right:0px;bottom:0px; } </style> </head> <body style="text-align:center;"> 俺是浮動條 俺是浮動條2 俺是浮動條3 俺是浮動條4 afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br>afosdhfosdhg<br> afosdhfosdhg<br> </body> </html>
[Ctrl+A 全選 注:如需引入外部Js需重新整理才能執行]
ps:
這一作的技術含量較前兩個更低......沒辦法,JS本來的目的之一就是特效....

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.