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/ ...
随机推荐
- Managing linux Shell Jobs
Managing Shell Jobs When moving jobs between the foreground and background, it may be useful to ha ...
- cogs 1008 贪婪大陆
/* 不要思维定视 盯着线段树维护l r 的ans不放 显然没法区间合并 换一种思路 如果打暴力的话 O(nm) 每次询问 扫一遍之前所有的修改 有交点则说明种数++ 接下来考虑如何优化 我们把每个区 ...
- SGU131--NYOJ435
参考blog http://m.blog.csdn.net/blog/u012760629/36927465 http://www.cppblog.com/menrowitianya/archive/ ...
- Ajax跨域请求中的Cookie问题(默认不带cookie等凭证)
1.原生Ajax请求方式,设置跨域请求附带详细参数 var xhr = new XMLHttpRequest(); xhr.open("POST", "http://xx ...
- (转)解析php中die(),exit(),return的区别
本篇文章是对php中die(),exit(),return的区别进行了详细的分析介绍,需要的朋友参考下 die()停止程序运行,输出内容exit是停止程序运行,不输出内容return是返回值d ...
- SQL 查询字段为值不为空
方法一sql="select * from table where id<>null " or sql="select ...
- PartialViewResult用法
后台代码 ) { IList<TestModel> lstTestModel = this.GetModelList(categoryid); return PartialView(lst ...
- HP SimpleXML
PHP SimpleXML PHP SimpleXML 处理最普通的 XML 任务,其余的任务则交由其它扩展处理. 什么是 PHP SimpleXML? SimpleXML 是 PHP 5 中的新特性 ...
- 【转】Debug和Release区别
VC下Debug和Release区别 最近写代码过程中,发现 Debug 下运行正常,Release 下就会出现问题,百思不得其解,而Release 下又无法进行调试,于是只能采用printf方式逐步 ...
- Java解析和生成XML
1.Jaxb处理java对象和xml之间转换常用的annotation有: @XmlType @XmlElement @XmlRootElement @XmlAttribute @XmlAccesso ...