PHPIN.NET

 找回密码
 立即注册
查看: 5112|回复: 0

[jQuery/Js/AJAX] 原生JS实现类似百度页面的分享效果

[复制链接]

469

主题

31

回帖

5507

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
5507
发表于 2015-5-28 19:46:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
原生JS实现类似百度页面的分享效果
  1. <!DOCTYPE html>
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  5.     <title>类似于网站的分享效果</title>
  6.     <style type="text/css">
  7.         #div1 {width:150px; height:200px;
  8.                background-color:#ff6a00;
  9.                position:absolute;
  10.                left:-150px;
  11.                top:50px;
  12.         }
  13.         #div2 {vertical-align:middle;
  14.                text-align:center;
  15.             width:20px;
  16.             height:60px;
  17.             background-color:#e64e4e;
  18.             position:absolute;
  19.             right:-20px;
  20.             top:80px;
  21.         }
  22.     </style>
  23.     <script type="text/javascript">
  24.         window.onload = function () {
  25.             var div1 = document.getElementById("div1");
  26.             var div2 = document.getElementById("div2");

  27.             div2.onmouseover=div1.onmouseover = function () {
  28.                 start(0);
  29.             };
  30.            div2.onmouseout= div1.onmouseout = function () {
  31.                 start(-150);
  32.             };
  33.         };
  34.         var time = null;
  35.         function start(target) {
  36.             var speed = 0;
  37.             if (div1.offsetLeft<target) {
  38.                 speed = 10;
  39.             }
  40.             if(div1.offsetLeft>target) {
  41.                 speed = -10;
  42.             }
  43.             if (div1.offsetLeft == target) {
  44.                 speed = 0;
  45.             }
  46.             clearInterval(time);
  47.             time = setInterval(function () {
  48.                 if (div1.offsetLeft== target) {
  49.                     clearInterval(time);
  50.                 }
  51.                 else {
  52.                     div1.style.left = div1.offsetLeft + speed + "px";
  53.                 }
  54.             }, 30);
  55.         }
  56.     </script>
  57. </head>
  58. <body>
  59.     <div id="div1">
  60.             <div id="div2">分享</div>
  61.     </div>
  62. </body>
  63. </html>
复制代码


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|PHPIN.NET ( 冀ICP备12000898号-14 )|网站地图

GMT+8, 2024-4-20 09:44

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表