zoukankan      html  css  js  c++  java
  • javaScript实现选中文字提示新浪微博分享的效果

    <!DOCTYPE html>
    <html  xmlns:wb="http://open.weibo.com/wb">
    <head>
        <meta charset="utf-8">
        <title>javaScript实现选中文字提示新浪微博分享的效果</title>
        <style type="text/css">
          #div1{ 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>
        <div id="div1"><img src="https://ss0.baidu.com/6ONWsjip0QIZ8tyhnq/it/u=163431486,1136892253&fm=58"></div>
        <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 oDiv = document.getElementById('div1');
    
                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(){
                            oDiv.style.display = 'block';
                            oDiv.style.left =left+'px';
                            oDiv.style.top = top +'px';
                        },1000)
                    } else{
                        oDiv.style.display = 'none';
                    }
                };
                oTxt.onclick =function(ev){
                    var ev =ev||window.event;
                    ev.cancelBubble = true;
                }
                document.onclick = function(){
                    oDiv.style.display = 'none';
                };
                //点击分享的实现
                oDiv.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>
  • 相关阅读:
    Java多线程设计模式(二)
    Java多线程设计模式(一)
    JAVA并发设计模式学习笔记(二)—— Single Threaded Execution Pattern
    JAVA并发设计模式学习笔记(一)—— JAVA多线程编程
    hibernate缓存机制(转载)
    web.xml中的contextConfigLocation的作用
    转:MAVEN常用命令
    eclipse 中添加自定义 classpath 的方法,以及 javac 和 java 的一些使用细节
    spring mvc 基于注解 配置默认 handlermapping
    viewport Meta Tag
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/7016002.html
Copyright © 2011-2022 走看看