国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > JS > 正文

JavaScript中實現無縫滾動、分享到側邊欄實例代碼

2024-05-06 16:30:16
字體:
來源:轉載
供稿:網友
本文給通過js代碼實現無縫滾動,側邊欄效果,在項目中經常會遇到,下面小編把代碼整理分享到VeVb武林網平臺,供大家參考
 

廢話不多說,直接給大家貼代碼了,代碼解決一起問題!

下面一段代碼給大家介紹js無縫滾動實例代碼:

代碼如下所示:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><style>*{margin:0px;padding:0px;}#div1{width:830px; height:166px; margin:50px auto;position:relative;background:white;overflow:hidden;}#div1 ul li{float:left; width:174px; height:166px; list-style:none;}ul{position:absolute;}</style><script>window.onload=function(){var oDiv=document.getElementById('div1');var oUl=oDiv.getElementsByTagName('ul')[0];var aLi=oUl.getElementsByTagName('li');var speed=3oUl.innerHTML=oUl.innerHTML+oUl.innerHTML;oUl.style.width=aLi[0].offsetWidth*aLi.length+'px';function move (){if(oUl.offsetLeft<-oUl.offsetWidth/2){oUl.style.left='0';}if(oUl.offsetLeft>0){oUl.style.left=-oUl.offsetWidth/2+'px';}oUl.style.left=oUl.offsetLeft+speed+'px';};var timer=setInterval(move,30);oDiv.onmouseover=function(){clearInterval(timer);};oDiv.onmouseout=function(){timer=setInterval(move,30);}document.getElementsByTagName('a')[0].onclick=function(){speed=-3;};document.getElementsByTagName('a')[1].onclick=function(){speed=3;};};</script></head><body><a href="javascipt:;">向左走</a><a href="javascipt:;">向右走</a><div id="div1"><ul><li><img src="images/b01.jpg" /></li><li><img src="images/b02.jpg" /></li><li><img src="images/b03.jpg" /></li><li><img src="images/b04.jpg" /></li><li><img src="images/b05.jpg" /></li></ul></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 xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>無標題文檔</title><style>#div1{width:100px; height:150px; background:#0F0; position:absolute; left:-100px;}#div1 span{position:absolute; width:20px; height:60px; line-height:20px; background:#00F; right:-20px; top:50px;}</style><script>window.onload=function(){var oDiv=document.getElementById('div1');oDiv.onmouseover=function(){startMove(10,0);}oDiv.onmouseout =function(){startMove(-10,-100);}}var timer=null;function startMove(speed,locall){var oDiv=document.getElementById('div1');clearInterval(timer);timer=setInterval(function(){if(oDiv.offsetLeft==locall){clearInterval(timer);}else{oDiv.style.left=oDiv.offsetLeft+speed+'px'; }},30);}</script></head><body><div id="div1"><span>分享到</span></div></body></html>

以上所述是小編給大家介紹的JavaScript中實現無縫滾動、分享到側邊欄實例代碼,代碼簡單易懂,有疑問歡迎給我留言,小編及時給您答復!



注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿克陶县| 无极县| 浠水县| 忻城县| 同心县| 凤台县| 安平县| 始兴县| 崇文区| 成都市| 天津市| 建德市| 孝感市| 荥经县| 丘北县| 凤阳县| 通榆县| 鞍山市| 贵溪市| 连平县| 包头市| 宁夏| 古交市| 赫章县| 临清市| 石阡县| 若羌县| 湖南省| 清水河县| 南皮县| 金门县| 肇源县| 虹口区| 弥渡县| 宜宾县| 东乡县| 万宁市| 新建县| 会泽县| 吴堡县| 林口县|