javascript 緩沖效果實現(xiàn)代碼 推薦
更新時間:2009年09月16日 12:57:19 作者:
緩沖效果就是實現(xiàn)一個頁面的由慢到快或由快到慢的過程。
菜鳥版代碼如下:
理解這段代碼就基本上掌握了
function f_s() {
var obj = document.getElementById("top");
obj.style.display = "block";
obj.style.height = "1px";
var sw = function () {
var s_width = parseInt(obj.style.height);
if (s_width < 350) {
obj.style.height = (s_width + Math.ceil((350 - s_width) / 15)) + "px";
}
else {
clearInterval(st);
}
}
var st = window.setInterval(sw, 1);
}
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
中級版本
/*
函數(shù)名稱: Scroll
Scroll(obj, h, s)
參數(shù)說明:
obj,[object] id值或?qū)ο? 必需
h,[height] 展開后的高度. 可選(默認(rèn)為200px)
s,[speed] 展開速度,值越小展開速度越慢. 可選(默認(rèn)為1.2){建議取值為1.1到2.0之間[例如:1.17]}.
函數(shù)返回值:
true 展開(對象的高度等于展開后的高度)
false 關(guān)閉(對象的高度等于原始高度)
*/
function Scroll(obj, h, s){
if(obj == undefined){return false;}
var h = h || 200;
var s = s || 1.2;
var obj = typeof(obj)=="string"?document.getElementById(obj):obj;
var status = obj.getAttribute("status")==null;
var oh = parseInt(obj.offsetHeight);
obj.style.height = oh;
obj.style.display = "block";
obj.style.overflow = "hidden";
if(obj.getAttribute("oldHeight") == null){
obj.setAttribute("oldHeight", oh);
}else{
var oldH = Math.ceil(obj.getAttribute("oldHeight"));
}
var reSet = function(){
if(status){
if(oh < h){
oh = Math.ceil(h-(h-oh)/s);
obj.style.height = oh+"px";
}else{
obj.setAttribute("status",false);
window.clearInterval(IntervalId);
}
}else{
obj.style.height = oldH+"px";
obj.removeAttribute("status");
window.clearInterval(IntervalId);
}
}
var IntervalId = window.setInterval(reSet,10);
return status;
}
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
高級版本
這個很全,不過,我是沒有看懂的.- -!!
http://www.cnblogs.com/cloudgamer/
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
打包下載
理解這段代碼就基本上掌握了
復(fù)制代碼 代碼如下:
function f_s() {
var obj = document.getElementById("top");
obj.style.display = "block";
obj.style.height = "1px";
var sw = function () {
var s_width = parseInt(obj.style.height);
if (s_width < 350) {
obj.style.height = (s_width + Math.ceil((350 - s_width) / 15)) + "px";
}
else {
clearInterval(st);
}
}
var st = window.setInterval(sw, 1);
}
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
中級版本
復(fù)制代碼 代碼如下:
/*
函數(shù)名稱: Scroll
Scroll(obj, h, s)
參數(shù)說明:
obj,[object] id值或?qū)ο? 必需
h,[height] 展開后的高度. 可選(默認(rèn)為200px)
s,[speed] 展開速度,值越小展開速度越慢. 可選(默認(rèn)為1.2){建議取值為1.1到2.0之間[例如:1.17]}.
函數(shù)返回值:
true 展開(對象的高度等于展開后的高度)
false 關(guān)閉(對象的高度等于原始高度)
*/
function Scroll(obj, h, s){
if(obj == undefined){return false;}
var h = h || 200;
var s = s || 1.2;
var obj = typeof(obj)=="string"?document.getElementById(obj):obj;
var status = obj.getAttribute("status")==null;
var oh = parseInt(obj.offsetHeight);
obj.style.height = oh;
obj.style.display = "block";
obj.style.overflow = "hidden";
if(obj.getAttribute("oldHeight") == null){
obj.setAttribute("oldHeight", oh);
}else{
var oldH = Math.ceil(obj.getAttribute("oldHeight"));
}
var reSet = function(){
if(status){
if(oh < h){
oh = Math.ceil(h-(h-oh)/s);
obj.style.height = oh+"px";
}else{
obj.setAttribute("status",false);
window.clearInterval(IntervalId);
}
}else{
obj.style.height = oldH+"px";
obj.removeAttribute("status");
window.clearInterval(IntervalId);
}
}
var IntervalId = window.setInterval(reSet,10);
return status;
}
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
高級版本
這個很全,不過,我是沒有看懂的.- -!!
http://www.cnblogs.com/cloudgamer/
[Ctrl+A 全選 注:引入外部Js需再刷新一下頁面才能執(zhí)行]
打包下載
您可能感興趣的文章:
- JavaScript實現(xiàn)的Tween算法及緩沖特效實例代碼
- JavaScript中的勻速運(yùn)動和變速(緩沖)運(yùn)動詳細(xì)介紹
- javascript 緩沖效果 實現(xiàn)代碼
- javascript 層展開/關(guān)閉,帶緩沖效果
- JavaScript實現(xiàn)仿新浪微博大廳和騰訊微博首頁滾動特效源碼
- javascript實現(xiàn)列表滾動的方法
- javaScript實現(xiàn)滾動新聞的方法
- javascript實現(xiàn)狀態(tài)欄文字首尾相接循環(huán)滾動的方法
- 純javascript實現(xiàn)四方向文本無縫滾動效果
- JavaScript實現(xiàn)滾動欄效果的方法
- JavaScript控制網(wǎng)頁平滑滾動到指定元素位置的方法
- JavaScript實現(xiàn)帶緩沖效果的隨屏滾動漂浮廣告代碼
相關(guān)文章
微信小程序如何使用Promise對wx.request()封裝詳解(附完整代碼)
微信小程序的wx.request是微信小程序最早生成的數(shù)據(jù)庫傳輸模式,數(shù)據(jù)傳輸簡單明確,下面這篇文章主要給大家介紹了關(guān)于微信小程序如何使用Promise對wx.request()封裝的相關(guān)資料,需要的朋友可以參考下2023-03-03Javascript數(shù)組方法reduce的妙用之處分享
這篇文章主要給大家介紹了關(guān)于Javascript數(shù)組方法reduce的妙用之處,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Javascript具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06詳解Typescript 內(nèi)置的模塊導(dǎo)入兼容方式
這篇文章主要介紹了詳解Typescript 內(nèi)置的模塊導(dǎo)入兼容方式,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05JS中mouseover和mouseout多次觸發(fā)問題如何解決
這篇文章主要介紹了JS中mouseover和mouseout多次觸發(fā)問題如何解決的相關(guān)資料,非常不錯具有參考借鑒價值,需要的朋友可以參考下2016-06-06