Home > Article > Web Front-end > Example tutorial on realizing Sina Weibo sharing effect in JS
This article mainly introduces in detail JavaScript to realize the selected text prompt Sina Weibo sharing effect, which has certain reference value. Interested friends can refer to it
The example in this article shares the JS Sina Weibo sharing function for your reference. The specific content is as follows
<!DOCTYPE html> <html xmlns:wb="http://open.weibo.com/wb"> <head> <meta charset="utf-8"> <title>javaScript实现选中文字提示新浪微博分享的效果</title> <style type="text/css"> #p1{ position: absolute; left: 0;top: 0; display: none;} </style> </head> <body> <p id="txt"> 一直对json的使用方法迷迷糊糊,知道一些简单的使用方法,有时用起来非常easy把自己搞混。今天专门查了一下相关的JSON的资料及使用方法,总结记录下来。JSON并非一种编程语言。能够理解成它是一种数据格式。尽管具有同样的语法形式。可是JSON并不属于JavaScript。并且。并非全部的JavaScript才使用JSON,非常多编程语言都有针对JSON的解析器和序列化器。JSON的语法能够表示三种类型值: </p> <p id="p1"><img src="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=163431486,1136892253&fm=58"></p> <script type="text/javascript"> window.onload=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; } } </script> </body> </html>
The above is the detailed content of Example tutorial on realizing Sina Weibo sharing effect in JS. For more information, please follow other related articles on the PHP Chinese website!