js實(shí)現(xiàn)類似iphone的網(wǎng)頁滑屏解鎖功能示例【附源碼下載】-創(chuàng)新互聯(lián)

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

創(chuàng)新互聯(lián)公司專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于做網(wǎng)站、網(wǎng)站設(shè)計(jì)、睢寧縣網(wǎng)絡(luò)推廣、成都微信小程序、睢寧縣網(wǎng)絡(luò)營銷、睢寧縣企業(yè)策劃、睢寧縣品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎(jiǎng);創(chuàng)新互聯(lián)公司為所有大學(xué)生創(chuàng)業(yè)者提供睢寧縣建站搭建服務(wù),24小時(shí)服務(wù)熱線:13518219792,官方網(wǎng)址:muchs.cn

iphone 的出現(xiàn),打破了人們的用戶體驗(yàn),這一用戶體驗(yàn)也延伸到了網(wǎng)頁設(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就可以完成,我在這里也簡單實(shí)現(xiàn)了一個(gè),基本功能如下

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

效果圖基本如下:

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

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

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

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

<!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 = "請輸入評(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 = "請輸入評(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" >
  <textarea id="comment_text" rows=5 ></textarea>
</div>
</div>
</body>
</html>

本文名稱:js實(shí)現(xiàn)類似iphone的網(wǎng)頁滑屏解鎖功能示例【附源碼下載】-創(chuàng)新互聯(lián)
標(biāo)題URL:http://muchs.cn/article12/degpdc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航、定制網(wǎng)站、做網(wǎng)站、響應(yīng)式網(wǎng)站、App設(shè)計(jì)、商城網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

營銷型網(wǎng)站建設(shè)