js实现类似iphone的网页滑屏解锁功能示例【附源码下载】
这篇文章主要介绍了js实现类似iphone的网页滑屏解锁功能,结合完整实例形式分析了javascript动态操作页面元素实现解锁效果的相关实现技巧,并附带供读者源码下载参考,需要的朋友可以参考下
本文实例讲述了js实现类似iphone的网页滑屏解锁功能。分享给大家供大家参考,具体如下:
iphone 的出现,打破了人们的用户体验,这一用户体验也延伸到了网页设计上。最近看到很多blog的评论都用类似iphone滑动解锁的方式实现。只有滑动解锁之后才能评论,或者做其他的事情。这个功能的实现,其实并不麻烦,关键是要有好的美工,做出好的滑动图片,然后javascript配合CSS就可以完成,我在这里也简单实现了一个,基本功能如下
1. 打开页面时隐藏评论框,你可以做成disable形式,下载源码后可以修改。
2. 滑动解锁图片,显示评论框,你可以做成让textarea字段enable方式。
3. 采用原生javascript实现,兼容ie,firefox,chrome,safari.
效果图基本如下:
你可以改动部分源代码测试,加入你自己想要的逻辑。
源代码贴在下面,你也可以在文章的最后下载:
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "TR/xhtml1/DTD/xhtml1-transitional.dtd" html xmlns="1999/xhtml" head meta http-equiv="Content-Type" content="text/html; charset=utf-8" / js滑屏解锁 /title style type="text/css" #ment{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 () ment = document.getElementById("ment"); var oLock = document.getElementById("lock"); var oBtn = oLock.getElementsByTagName("span")[0]; ment=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="ment" div id="lock" span /span /div div id="comment" textarea id="comment_text" rows=5 /textarea /div /div /body /html
源码点击此处。
更多关于jQuery相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》及《》
希望本文所述对大家jQuery程序设计有所帮助。