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

首頁(yè) > 編程 > JavaScript > 正文

js實(shí)現(xiàn)類似iphone的網(wǎng)頁(yè)滑屏解鎖功能示例【附源碼下載】

2019-11-19 11:21:59
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

本文實(shí)例講述了js實(shí)現(xiàn)類似iphone的網(wǎng)頁(yè)滑屏解鎖功能。分享給大家供大家參考,具體如下:

iphone 的出現(xiàn),打破了人們的用戶體驗(yàn),這一用戶體驗(yàn)也延伸到了網(wǎng)頁(yè)設(shè)計(jì)上。最近看到很多blog的評(píng)論都用類似iphone滑動(dòng)解鎖的方式實(shí)現(xiàn)。只有滑動(dòng)解鎖之后才能評(píng)論,或者做其他的事情。這個(gè)功能的實(shí)現(xiàn),其實(shí)并不麻煩,關(guān)鍵是要有好的美工,做出好的滑動(dòng)圖片,然后javascript配合CSS就可以完成,我在這里也簡(jiǎn)單實(shí)現(xiàn)了一個(gè),基本功能如下

1. 打開頁(yè)面時(shí)隱藏評(píng)論框,你可以做成disable形式,下載源碼后可以修改。
2. 滑動(dòng)解鎖圖片,顯示評(píng)論框,你可以做成讓textarea字段enable方式。
3. 采用原生javascript實(shí)現(xiàn),兼容ie,firefox,chrome,safari.

效果圖基本如下:

你可以改動(dòng)部分源代碼測(cè)試,加入你自己想要的邏輯。

源代碼貼在下面,你也可以在文章的最后下載:

<!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>yihaomen.com js滑屏解鎖</title><style type="text/css"> #slider_comment{position:relative;width:426px;height:640px;margin:10px auto;}#lock{width:200px;height:30px;border:1px dashed #ccc;line-height:30px;}#lock span{position:absolute;width:45px;height:30px;cursor:pointer;background:url(img/arrow.png) no-repeat;}</style><script type="text/javascript"> window.onload = function (){  var slider_comment = document.getElementById("slider_comment");  var oLock = document.getElementById("lock");  var oBtn = oLock.getElementsByTagName("span")[0];  var comment=document.getElementById('comment');  var disX = 0;  var maxL = oLock.clientWidth - oBtn.offsetWidth;    oBtn.onmousedown = function (e)  {    var e = e || window.event;    disX = e.clientX - this.offsetLeft;    document.onmousemove = function (e)    {      var e = e || window.event;      var l = e.clientX - disX;      l < 0 && (l = 0);      l > maxL && (l = maxL);            oBtn.style.left = l + "px";            oBtn.offsetLeft == maxL && (comment.style.display="block",oLock.innerHTML = "請(qǐng)輸入評(píng)論內(nèi)容");      return false;    };    document.onmouseup = function ()    {      document.onmousemove = null;      document.onmouseup = null;      oBtn.releaseCapture && oBtn.releaseCapture();      oBtn.offsetLeft > maxL / 2 ?        startMove(maxL, function ()        {          comment.style.display="block";          oLock.innerHTML = "請(qǐng)輸入評(píng)論內(nèi)容";          oLock.style.display = "block";        }) :        startMove(0)    };    this.setCapture && this.setCapture();    return false  };  function startMove (iTarget, onEnd)  {    clearInterval(oBtn.timer);    oBtn.timer = setInterval(function ()    {      doMove(iTarget, onEnd)    }, 30)  }  function doMove (iTarget, onEnd)  {    var iSpeed = (iTarget - oBtn.offsetLeft) / 5;    iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed);    iTarget == oBtn.offsetLeft ? (clearInterval(oBtn.timer), onEnd && onEnd()) : oBtn.style.left = iSpeed + oBtn.offsetLeft + "px"  }};</script></head><body><div id="slider_comment"><div id="lock"><span></span></div><div id="comment" style="width:500px;height:200px;display:none;">  <textarea id="comment_text" rows=5 style="width:500px;height:200px;border:1px solid #ccc;"></textarea></div></div></body></html>

源碼點(diǎn)擊此處本站下載。

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery頁(yè)面元素操作技巧匯總》、《jQuery常見事件用法與技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》及《jquery選擇器用法總結(jié)

希望本文所述對(duì)大家jQuery程序設(shè)計(jì)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 信阳市| 东丰县| 闽清县| 新建县| 五常市| 板桥市| 仙游县| 醴陵市| 南雄市| 邢台县| 建阳市| 乐昌市| 长沙县| 宣城市| 南靖县| 嘉荫县| 福建省| 长子县| 寿阳县| 镇沅| 奉新县| 清水县| 荥阳市| 辽源市| 连云港市| 九江县| 三明市| 闸北区| 汝阳县| 桐乡市| 宁化县| 婺源县| 辽宁省| 阳朔县| 宝丰县| 呈贡县| 桑植县| 承德县| 栖霞市| 宜良县| 嘉鱼县|