javascript 实现分享功能
1、面向过程分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
} ul,li{
list-style: none;
} .share {
position: absolute;
width: 300px;
height: 200px; left: -270px;
} .share span{
padding-top: 70px; width: 30px;
height: 130px; display: block;
float: left; border-radius:0 10px 10px 0; background-color: pink;
color: #fff;
text-align: center;
} .sharecont{
width: 270px;
height: 200px; float: left; background: grey;
} </style>
</head>
<body> <div class="share" id="share">
<div class="sharecont"></div>
<span id="share">分享到:</span>
</div>
<script>
/**
* 练习javascript中运动的概念
* javascript 要实现运动运动设计到的两个地方:
* 1、div 必须要设置为position: absolute
* 2、使用定时器来完成
* 3、以后判断条件尽量用===的形式来判断到达终点
*/
window.onload = function () {
var share = document.getElementById('share');
var timer = null; function startMove (iTarget) {
clearInterval(timer);
var speed = 0;
timer = setInterval(function(){
if( share.offsetLeft < iTarget ){
speed = 10;
}else{
speed = -10;
} if( share.offsetLeft === iTarget ){
clearInterval(timer);
}else{
share.style.left = share.offsetLeft + speed + "px";
}
},30);
} share.onmouseover = function () {
startMove(0);
};
share.onmouseout = function () {
startMove(-270);
};
};
</script>
</body> </html>
2、使用面向对象改写以上程序
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
} ul,li{
list-style: none;
} .share {
position: absolute;
width: 300px;
height: 200px; left: -270px;
} .share span{
padding-top: 70px; width: 30px;
height: 130px; display: block;
float: left; border-radius:0 10px 10px 0; background-color: #6ed8e5;
color: #fff;
text-align: center;
} .sogoushare {
top: 300px;
} .sogoushare span{
background-color: #3acdb0;
} .sharecont{
width: 270px;
height: 200px; float: left; background: grey;
} </style>
</head>
<body> <div class="share" id="baidushare">
<div class="sharecont"></div>
<span>分享到</span>
</div> <div class="share sogoushare" id="sogoushare">
<div class="sharecont"></div>
<span>分享到</span>
</div> <script> /**
* 练习javascript中运动完成面向对象的分享功能
* overItarget 传入移入的到达目标值
* outItarget 传入移出的目标值
*/ function Share (id, overItarget, outItarget) {
this.share = document.getElementById(id);
this.timer = null;
this.speed = 0;
var that = this; this.share.onmouseover = function () {
that.startMove(overItarget);
}; this.share.onmouseout = function () {
that.startMove(outItarget);
};
} Share.prototype.startMove = function(iTarget) {
clearInterval(this.timer); var that = this;
this.timer = setInterval(function(){ if( that.share.offsetLeft < iTarget ){
this.speed = 10;
}else{
this.speed = -10;
} if( that.share.offsetLeft === iTarget ){
clearInterval(this.timer);
}else{
that.share.style.left = that.share.offsetLeft + this.speed + "px";
}
},30);
}; window.onload = function () { var baiduShare = new Share("baidushare",0,-270);
var sogouShare = new Share("sogoushare",0,-270); };
</script>
</body>
javascript 实现分享功能的更多相关文章
- 微信分享功能引入页面-控制分享时候调用的标题、图片、url和微信按钮隐藏显示控制
1.设置分享调用的标题.图片.url预览. 2.控制右上角三个点按钮的隐藏显示(和底部工具栏的显示隐藏--未测试). 3.判断网页是否在微信中被调用. <!doctype html> &l ...
- 微信JS-SDK实际分享功能
为了净化网络,整顿诱导分享及诱导关注行为,微信于2014年12月30日发布了<微信公众平台关于整顿诱导分享及诱导关注行为的公告>,微信平台开发者发现,原有的微信分享功能不能用了,在ipho ...
- js分享功能
引用JiaThis的分享功能: 直接在想要放置分享功能的地方加上如下代码即可: <!-- JiaThis Button BEGIN --> <div class="jiat ...
- js分享功能(微信,QQ,微博,空间,豆瓣等)
日常编程中,我们可能会碰到项目中的分享功能,各大平台都有分享接口和文档说明,当然也有一些一键分享插件,例如:sosh,iShare.js等等 但有些同学不想引用插件,那么我整理了一些常用的分享至平台功 ...
- H5分享功能
web端分享功能 https://www.cnblogs.com/sdcs/p/8328367.html H5分享功能 公司里面做web开发经常会做H5页面,今天整理分享一下. 微信公众号平台 步骤一 ...
- 12个实用的 JavaScript 框架分享给前端开发者
JavaScript库是预先编写的 JavaScript 工具代码,让开发者可以更容易开发 JavaScript 应用.这个列表我们列出了2017年1月份功能丰富的 JavaScript 库,可以帮助 ...
- ThinkPHP5集成JS-SDK实现微信自定义分享功能
最近开发一个项目,需要将链接分享给好友时能够自定义标题.简介和logo,现将ThinkPHP5集成JS-SDK实现微信自定义分享功能的过程整理成文. 一.准备工作 1.认证的公众号 不管是订阅号还是服 ...
- 实现分享功能插件2---jiathis分享插件应用
博主原创:未经博主允许,不得转载 在上一篇的博文中分享了如何用百度分享插件实现分享功能,现在展示用jiathis进行实现分享功能: 主要代码如下: <body> <div class ...
- MUI 分享功能(微信、QQ 、朋友圈)
配置文件:manifest.json plus ->plugins 下边 "share": {/*配置应用使用分享功能,参考http://ask.dcloud.net.cn/ ...
随机推荐
- 【转】prufer编码
既然有人提到了,就顺便学习一下吧,来源:http://greatkongxin.blog.163.com/blog/static/170097125201172483025666/ 一个含有n个点的完 ...
- mongodb入门教程
title: mongodb入门教程 date: 2016-04-06 14:47:18 tags: --- 为什么要认识呢,因为这玩意就一傻逼 借用一下百科的介绍 MongoDB 是一个介于关系数据 ...
- hdu 2186
#include <iostream> using namespace std; int main() { int a,b,c,k1,k2,k3,m,n; cin>>m; wh ...
- bootstrap初探
bootstrap资源 http://getbootstrap.com http://github.com/twbs http://www.bootcss.com bootstrap栅格系统 容器:流 ...
- 腾讯云升级到PHP7
1.删除之前安装的PHP yum remove php* php-common 2.安装yum源 rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel ...
- 【转】Android开源项目 分类 便于查看
之前转载了一个开源项目的文章,发现那些都是没有系统的总结,这里又转载一篇有系统总结的文章. Android开源项目系列汇总已完成,包括: Android开源项目第一篇——个性化控件(View)篇 An ...
- jQuery 基本实现功能模板
下面是列出了基本功能的实现 <!DOCTYPE html> <html> <head> <script src="http://libs.baidu ...
- c - 水仙花数.
#include <stdio.h> #include <math.h> /* *打印出所有的“水仙花数” ,所谓“水仙花数”是指一个三位数,其各位数字立方和等于该数本身. * ...
- 问题: Type mismatch in key from map: expected org.apache.hadoop.io.Text, recieved org.apache.hadoop.io.LongWritable 解决方案
在Job中添加相应的输入类型,例如: job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(IntWritable.clas ...
- Oracle 11g随Redhat 5系统自动启动与关闭的设置方法
最近,ORACLE系统基本调试通过,是时候设置ORACLE随RHEL自动启动与关闭服务的时候了,之所以把这个任务放在最后来做,是因为我觉得这个应该不会很难,但真正实施起来,还是遇到了个不小的障碍:写好 ...