如何用JavaScript实现类似iPhone的网页滑屏解锁功能?

2026-04-09 20:571阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计850个文字,预计阅读时间需要4分钟。

如何用JavaScript实现类似iPhone的网页滑屏解锁功能?

原文示例:本文实例讲述了JS实现类似iPhone的网页滑动解锁功能。分享给大家供大家参考,具体如下:iPhone的出现,打破了人们的用户体验,这一用户体验也延续到了网页设计上。最近看到很多B端...

改写后:本文通过实例展示了如何用JS制作类似iPhone的网页滑动解锁效果。以下为具体内容:iPhone的问世,颠覆了用户的使用体验,这种体验也影响了网页设计。近期发现不少B端设计都在借鉴这种滑动解锁方式。

本文实例讲述了js实现类似iphone的网页滑屏解锁功能。分享给大家供大家参考,具体如下:

iphone 的出现,打破了人们的用户体验,这一用户体验也延伸到了网页设计上。最近看到很多blog的评论都用类似iphone滑动解锁的方式实现。只有滑动解锁之后才能评论,或者做其他的事情。这个功能的实现,其实并不麻烦,关键是要有好的美工,做出好的滑动图片,然后javascript配合CSS就可以完成,我在这里也简单实现了一个,基本功能如下

1. 打开页面时隐藏评论框,你可以做成disable形式,下载源码后可以修改。
2. 滑动解锁图片,显示评论框,你可以做成让textarea字段enable方式。
3. 采用原生javascript实现,兼容ie,firefox,chrome,safari.

效果图基本如下:

如何用JavaScript实现类似iPhone的网页滑屏解锁功能?

你可以改动部分源代码测试,加入你自己想要的逻辑。

源代码贴在下面,你也可以在文章的最后下载:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="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 = "请输入评论内容"); 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 = "请输入评论内容"; 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相关内容感兴趣的读者可查看本站专题:《jQuery页面元素操作技巧汇总》、《jQuery常见事件用法与技巧总结》、《jQuery常用插件及用法总结》、《jQuery扩展技巧总结》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。

本文共计850个文字,预计阅读时间需要4分钟。

如何用JavaScript实现类似iPhone的网页滑屏解锁功能?

原文示例:本文实例讲述了JS实现类似iPhone的网页滑动解锁功能。分享给大家供大家参考,具体如下:iPhone的出现,打破了人们的用户体验,这一用户体验也延续到了网页设计上。最近看到很多B端...

改写后:本文通过实例展示了如何用JS制作类似iPhone的网页滑动解锁效果。以下为具体内容:iPhone的问世,颠覆了用户的使用体验,这种体验也影响了网页设计。近期发现不少B端设计都在借鉴这种滑动解锁方式。

本文实例讲述了js实现类似iphone的网页滑屏解锁功能。分享给大家供大家参考,具体如下:

iphone 的出现,打破了人们的用户体验,这一用户体验也延伸到了网页设计上。最近看到很多blog的评论都用类似iphone滑动解锁的方式实现。只有滑动解锁之后才能评论,或者做其他的事情。这个功能的实现,其实并不麻烦,关键是要有好的美工,做出好的滑动图片,然后javascript配合CSS就可以完成,我在这里也简单实现了一个,基本功能如下

1. 打开页面时隐藏评论框,你可以做成disable形式,下载源码后可以修改。
2. 滑动解锁图片,显示评论框,你可以做成让textarea字段enable方式。
3. 采用原生javascript实现,兼容ie,firefox,chrome,safari.

效果图基本如下:

如何用JavaScript实现类似iPhone的网页滑屏解锁功能?

你可以改动部分源代码测试,加入你自己想要的逻辑。

源代码贴在下面,你也可以在文章的最后下载:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="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 = "请输入评论内容"); 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 = "请输入评论内容"; 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相关内容感兴趣的读者可查看本站专题:《jQuery页面元素操作技巧汇总》、《jQuery常见事件用法与技巧总结》、《jQuery常用插件及用法总结》、《jQuery扩展技巧总结》及《jquery选择器用法总结》

希望本文所述对大家jQuery程序设计有所帮助。