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

首頁 > 開發(fā) > JS > 正文

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

2024-05-06 16:51:59
字體:
來源:轉載
供稿:網(wǎng)友

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

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

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

效果圖基本如下:

js,iphone,滑屏解鎖,源碼下載

js,iphone,滑屏解鎖,源碼下載

你可以改動部分源代碼測試,加入你自己想要的邏輯。

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

<!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 = "請輸入評論內(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 = "請輸入評論內(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>

源碼點擊此處本站下載

希望本文所述對大家jQuery程序設計有所幫助。


注:相關教程知識閱讀請移步到JavaScript/Ajax教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 岳普湖县| 道真| 名山县| 苏尼特右旗| 隆子县| 修武县| 广宗县| 富源县| 大埔县| 古浪县| 宁都县| 中方县| 重庆市| 福贡县| 渝中区| 北碚区| 汪清县| 阿拉尔市| 渑池县| 巫溪县| 连江县| 唐河县| 安宁市| 永吉县| 阆中市| 比如县| 景泰县| 平阳县| 墨脱县| 象州县| 大理市| 手游| 车致| 满城县| 杭锦旗| 介休市| 吉水县| 景洪市| 昌平区| 隆德县| 广宁县|