>  기사  >  웹 프론트엔드  >  JS를 사용하여 간단한 팁 기능 구현

JS를 사용하여 간단한 팁 기능 구현

php中世界最好的语言
php中世界最好的语言원래의
2018-04-18 14:02:462100검색

이번에는 JS를 사용하여 간단한 팁 기능을 구현하는 방법에 대한 Notes를 함께 살펴보겠습니다.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
 
<head>
  <metahttp-equiv="Content-Type"content="text/html;"/>
  <title>打赏</title>
  <styletype="text/css">
    #dsSidebar {
      z-index: 999999;
      top: 18%;
      width: 200px;
      height: 200px;
      position: fixed;
      right: -200px;
    }
 
    #dsBtn {
      z-index: 999999;
      width: 30px;
      height: 58px;
      left: -30px;
      top: 80px;
      line-height: 28px;
      position: absolute;
    }
 
    .dsPanels {
      margin: 0px auto;
      overflow: hidden;
    }
 
    .dsPanel {
      float: left;
      margin: 0px 0px;
      padding: 12px 0px;
      text-align: center;
      background: #ffeedd;
      border-color: #ffeedd;
      border-radius: 8px;
    }
 
    .dsPanel-highlight {
      margin-top: 0;
      margin-bottom: 0;
      padding-left: 10px;
      padding-right: 10px;
      width: 160px;
      border: 8px solid #fd935c;
    }
 
    .dsPanel-button {
      display: block;
      font-size: 16px;
      font-weight: 500;
      color: #ffeedd;
      text-align: center;
      text-decoration: none;
      text-shadow: 0 1px rgba(black, .1);
      background: #fd935c;
      border-bottom: 2px solid #cf7e3b;
      border-color: rgba(black, .15);
      border-radius: 4px;
    }
 
    .dsPanel-title {
      width: 128px;
      margin: -15px auto 15px;
      padding-bottom: 0px;
      line-height: 22px;
      font-size: 14px;
      font-weight: bold;
      color: #ffeedd;
      text-shadow: 0 1px rgba(black, .05);
      background: #fd935c;
      border-radius: 0 0 4px 4px;
    }
  </style>
  <script>
    function moveBtn() {
      var dsBtn = document.getElementById("dsBtn");
      var now = new Date();
      var times = now.getTime();
      var offsetSize = Math.sin(times / 380.0) * 15 + 45;
      var radius = Math.sin(times / 380.0) * 18 + 24;
      dsBtn.style.left = -offsetSize + 'px';
      dsBtn.style.width = offsetSize + 'px';
      dsBtn.style.borderRadius = radius + 'px';
      setTimeout(moveBtn, 60);
    }
 
    var dsSidebarTimer = null;
    var dsSidebarOffsetRight = -200;
    function startMove(dsSidebarTarget, dsSidebarSpeed) {
      clearTimeout(dsSidebarTimer);
      function doMove() {
        var dsSidebar = document.getElementById('dsSidebar');
        dsSidebarSpeed *= 0.9;
        if (dsSidebarSpeed > -1 && dsSidebarSpeed <0) {
          dsSidebarSpeed = -1;
        } else if (dsSidebarSpeed < 1 && dsSidebarSpeed > 0) {
          dsSidebarSpeed = 1;
        }
        dsSidebarOffsetRight = dsSidebarOffsetRight + dsSidebarSpeed;
        if (dsSidebarSpeed > 0 && dsSidebarOffsetRight >= dsSidebarTarget) {
          dsSidebarOffsetRight = dsSidebarTarget;
          dsSidebar.style.right = dsSidebarOffsetRight + 'px';
        } else if (dsSidebarSpeed <0&& dsSidebarOffsetRight <= dsSidebarTarget) {
          dsSidebarOffsetRight=dsSidebarTarget;
          dsSidebar.style.right=dsSidebarOffsetRight+ &#39;px&#39;;
        } else {
          dsSidebar.style.right=dsSidebarOffsetRight+ &#39;px&#39;;
          dsSidebarTimer=setTimeout(doMove, 30);
        }
      }
      doMove();
    }
    document.getElementById(&#39;dsImg&#39;).onload=function() {
      vardsSidebar=document.getElementById(&#39;dsSidebar&#39;);
      dsSidebar.onmouseover=function() {
        startMove(0, 24);
      }
      dsSidebar.onmouseout=function() {
        startMove(-200, -24);
      }
      moveBtn();
    }
  </script>
</head>
 
<body>
  <pid="dsSidebar">
    <pclass="dsPanels">
      <pclass="dsPanel dsPanel-highlight">
        <pclass="dsPanel-title">喜欢请用微信打赏</p>
        <imgid=&#39;dsImg&#39;src="http://files.cnblogs.com/files/eritpang/weixin.bmp"alt=""width="160"height="160"/>
      </p>
    </p>
    <spanclass="dsPanel-button"id=&#39;dsBtn&#39;><b>打<br/>赏</b></span>
  </p>
</body>
 
</html>

이 기사의 사례를 읽으신 후 방법을 마스터하셨다고 생각합니다. 더 흥미로운 정보를 보려면 PHP 중국어 웹사이트의 다른 관련 기사를 주목하세요!

추천 자료:

JS 유형을 변환하는 방법

js는 새로 고침 카운트다운을 방지합니다.

JS 배열은 지정된 요소를 삭제합니다

위 내용은 JS를 사용하여 간단한 팁 기능 구현의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.