这篇文章主要为大家详细介绍了JavaScript实现选中文字提示新浪微博分享效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文实例为大家分享了JS新浪微博分享功能,供大家参考,具体内容如下
javaScript实现选中文字提示新浪微博分享的效果#p1{ position: absolute; left: 0;top: 0; display: none;}
一直对json的使用方法迷迷糊糊,知道一些简单的使用方法,有时用起来非常easy把自己搞混。今天专门查了一下相关的JSON的资料及使用方法,总结记录下来。JSON并非一种编程语言。能够理解成它是一种数据格式。尽管具有同样的语法形式。可是JSON并不属于JavaScript。并且。并非全部的JavaScript才使用JSON,非常多编程语言都有针对JSON的解析器和序列化器。JSON的语法能够表示三种类型值:
window.οnlοad=function(){
function selectText(){
if(document.selection){
//兼容ie
return document.selection.createRange().text;
} else{
//标准的获取方法
return window.getSelection().toString();
}
}
var oTxt = document.getElementById('txt');
var op = document.getElementById('p1');
oTxt.onmouseup = function(ev){
var ev =ev||window.event;
var top = ev.clientY;
var left = ev.clientX;
if(selectText().length>10){
console.log(selectText())
setTimeout(function(){
op.style.display = 'block';
op.style.left =left+'px';
op.style.top = top +'px';
},1000)
} else{
op.style.display = 'none';
}
};
oTxt.onclick =function(ev){
var ev =ev||window.event;
ev.cancelBubble = true;
}
document.onclick = function(){
op.style.display = 'none';
};
//点击分享的实现
op.onclick = function(){
window.location.href='http://service.weibo.com/share/share.php?url=http%3A%2F%2Flocalhost%3A63342%2Fjs2%2Fpicscroll.html&type=icon&language=zh_cn&searchPic=true&style=simple'+selectText()+window.location.href;
}
}