JS模仿騰訊圖片站的圖片翻頁(yè)按鈕效果完整實(shí)例
本文實(shí)例講述了JS模仿騰訊圖片站的圖片翻頁(yè)按鈕效果。分享給大家供大家參考,具體如下:
運(yùn)行效果截圖如下:
具體代碼如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>模仿騰訊圖片翻頁(yè)</title> <style type="text/css"> *{ margin:none; padding:none; } body{ background:#000000; } #tip{ position:absolute; width:564px; height:362px; top:-362px; background:url(../img/TencentImg/tipLayer.png); } #left{ position:absolute; width:101px; height:95px; background:url(../img/TencentImg/left.png); border:1px solid #f2f2f2; display:none; cursor:hand; } #right{ position:absolute; width:101px; height:95px; background:url(../img/TencentImg/right.png); border:1px solid #f2f2f2; display:none; cursor:hand; } #mouseXPosition{ width:30px; height:20px; color:#ffffff; display:inline; } #mouseYPosition{ width:30px; height:20px; color:#ffffff; display:inline; } #divTop{ width:30px; height:20px; color:#ffffff; display:inline; } </style> <script type="text/javascript"> function init(){ var ml = document.body.clientWidth/2 - 40; document.getElementById("left").style.pixelTop = 300; document.getElementById("right").style.pixelTop = 300; document.getElementById("left").style.pixelLeft = ml - 101*4; document.getElementById("right").style.pixelLeft = ml + 101*4; var tip = document.getElementById("tip"); var initH = (document.body.clientWidth - tip.offsetWidth)/2; document.getElementById("tip").style.left = initH; document.getElementById("tip").style.pixelTop = -362; } function mousePosition(ev){ if(ev.pageX || ev.pageY){ return {x:ev.pageX, y:ev.pageY}; } return { x:ev.clientX + document.body.scrollLeft - document.body.clientLeft, y:ev.clientY + document.body.scrollTop - document.body.clientTop }; } document.onmousemove = mouseMove; function mouseMove(e){ e = e || window.event; var mousePos = mousePosition(e); var mid = document.body.clientWidth/2; document.getElementById('mouseXPosition').innerHTML = mousePos.x; document.getElementById('mouseYPosition').innerHTML = mousePos.y; if(mousePos.x < mid){ document.getElementById("left").style.display = "block"; document.getElementById("right").style.display = "none"; }else if(mousePos.x > mid){ document.getElementById("right").style.display = "block"; document.getElementById("left").style.display = "none"; } } function show(){ if(document.getElementById("tip").style.pixelTop < 80){ document.getElementById("tip").style.pixelTop += 20; document.getElementById("divTop").innerHTML = document.getElementById("tip").style.pixelTop; setTimeout("show()",10) } } function hide(){ if(document.getElementById("tip").style.pixelTop > -362){ document.getElementById("tip").style.pixelTop -= 20; document.getElementById("divTop").innerHTML = document.getElementById("tip").style.pixelTop; setTimeout("hide()",10) } } </script> </head> <body onload="init()"> <div id = "left" onclick="hide()"></div> <div id = "right" onclick="show()"></div> <span style = "color:#ffffff;">鼠標(biāo) X 軸:</span> <div id="mouseXPosition">0</div><br/> <span style = "color:#ffffff">鼠標(biāo) Y 軸:</span> <div id="mouseYPosition">0</div><br/> <span style = "color:#ffffff;font-size:13px;">圖片上邊距:</span> <div id = "divTop">0</div> <div id = "tip">0</div> </body> </html>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
微信小程序停止其他視頻播放當(dāng)前視頻的實(shí)例代碼
這篇文章主要介紹了微信小程序停止其他視頻播放當(dāng)前視頻的實(shí)例代碼,代碼簡(jiǎn)單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-12-12JavaScript高級(jí)程序設(shè)計(jì) 讀書筆記之九 本地對(duì)象Array
本地對(duì)象Array,數(shù)組等操作函數(shù)2012-02-02js實(shí)現(xiàn)用戶輸入的小寫字母自動(dòng)轉(zhuǎn)大寫字母的方法
下面小編就為大家?guī)?lái)一篇js實(shí)現(xiàn)用戶輸入的小寫字母自動(dòng)轉(zhuǎn)大寫字母的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-01-01詳解如何在JavaScript中無(wú)縫地集成和使用Python代碼
這篇文章主要目標(biāo)是幫助諸位理解如何在JavaScript中無(wú)縫地集成和使用Python代碼,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2023-06-06解決option標(biāo)簽selected="selected"屬性失效的問(wèn)題
下面小編就為大家?guī)?lái)一篇解決option標(biāo)簽selected="selected"屬性失效的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧,希望對(duì)大家有所幫助2017-11-11JavaScript中的console.assert()函數(shù)介紹
這篇文章主要介紹了JavaScript中的console.assert()函數(shù)介紹,assert()函數(shù)是一個(gè)調(diào)試中經(jīng)常使用的斷言工具函數(shù),需要的朋友可以參考下2014-12-12layui 解決富文本框form表單提交為空的問(wèn)題
今天小編就為大家分享一篇layui 解決富文本框form表單提交為空的問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-10-10js實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)時(shí)圖片滾動(dòng)停止的方法
這篇文章主要介紹了js實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)時(shí)圖片滾動(dòng)停止的方法,可實(shí)現(xiàn)js滾動(dòng)特效中的鼠標(biāo)懸停停止圖片滾動(dòng)的功能,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-02-02