JS类小功能

工作中,总是要处理一些前端的小功能。都是网上搜的JS脚本

<script>
    //防止页面后退 
    history.pushState(null, null, document.URL);
    window.addEventListener('popstate', function () {
        history.pushState(null, null, document.URL);
    });
</script>

 

判断是否微信浏览器,相应显示与隐藏html元素

<script type="text/javascript">
    function is_weixn(){
        var ua = navigator.userAgent.toLowerCase();
        if(ua.match(/MicroMessenger/i)!="micromessenger") {
            var box=document.getElementById("notify"); //div or span 
            var box2=document.getElementById("submit"); //<input id="submit" type="submit" value="提 交"> 
            box.style.display="inline";
            box2.style.display="none";
        } else {
            return false;
        }
    }
</script>
<body onload="is_weixn()">

 

定时滚动的文本框:

<script type="text/javascript">
function startmarquee(lh,speed,delay,index){ 
    var t; 
    var p=false; 
    var o=document.getElementById("marqueebox"+index); 
    o.innerHTML+=o.innerHTML; 
    o.onmouseover=function(){p=true} 
    o.onmouseout=function(){p=false} 
    o.scrollTop = 0; 
    function start(){ 
        t=setInterval(scrolling,speed); 
        if(!p){ o.scrollTop += 1;} 
    } 
    function scrolling(){ 
        if(o.scrollTop%lh!=0){ 
            o.scrollTop += 1; 
            if(o.scrollTop>=o.scrollHeight/2) o.scrollTop = 0; 
        }else{ 
            clearInterval(t); 
            setTimeout(start,delay); 
        } 
    } 
    setTimeout(start,delay); 
} 
startmarquee(72,20,5000,0); 
</script>
<!-- html 部分-->
<div class="box" id="marqueebox0"> 
<div id="safetxt">...</div>
<div id="safetxt2">...</div>
</div>

 

posted @ 2017-03-14 11:03  枫若雪  阅读(210)  评论(0编辑  收藏  举报