美文网首页
Destoon框架中的一些JS

Destoon框架中的一些JS

作者: 郝特么冷 | 来源:发表于2017-09-25 15:48 被阅读74次

Destoon框架中的JS函数

  • 判断移动端类型
var UA = navigator.userAgent.toLowerCase();
  • 判断是不是IE浏览器
var isIE = (document.all && window.ActiveXObject && !window.opera) ? true : false;
  • 判断当前是不是webkit内核
var isGecko = UA.indexOf('webkit') != -1;
  • 判断当前的用户协议,主机名,端口
var DMURL = document.location.protocol + '//' + location.hostname + (location.port ? ':' + location.port : '') + '/';
  • 跳转函数
function Go(u) {
    window.location = u;
}
  • 带提示的跳转函数
function confirmURI(m, f) {
    if(confirm(m)) window.location = f;
}
  • 桌面通知属性
function Dnotification(id, url, icon, title, content) {
    if(window.webkitNotifications) {
        if(webkitNotifications.checkPermission() == 1) {
            window.onclick = function() {
                window.webkitNotifications.requestPermission(function() {
                    if(webkitNotifications.checkPermission() == 0) {
                        var N = window.webkitNotifications.createNotification(icon, title, content);
                        N.replaceId = id;
                        N.onclick = function() {
                            window.focus();
                            window.top.location = url;
                            N.cancel();
                        };
                        N.show();
                    }
                });
            };
        } else if(webkitNotifications.checkPermission() == 0) {
            var N = window.webkitNotifications.createNotification(icon, title, content);
            N.replaceId = id;
            N.onclick = function() {
                window.focus();
                window.top.location = url;
                N.cancel();
            };
            N.show();
        }
    }
}
  • 缓存机制
function set_cookie(n, v, d) {
    var e = '';
    var f = d ? d : 365;
    e = new Date((new Date()).getTime() + f * 86400000);
    e = "; expires=" + e.toGMTString();
    document.cookie = CKPrex + n + "=" + v + ((CKPath == "") ? "" : ("; path=" + CKPath)) + ((CKDomain == "") ? "" : ("; domain=" + CKDomain)) + e;
}

function get_cookie(n) {
    var v = '';
    var s = CKPrex + n + "=";
    if(document.cookie.length > 0) {
        o = document.cookie.indexOf(s);
        if(o != -1) {
            o += s.length;
            end = document.cookie.indexOf(";", o);
            if(end == -1) end = document.cookie.length;
            v = unescape(document.cookie.substring(o, end));
        }
    }
    return v;
}

function del_cookie(n) {
    var e = new Date((new Date()).getTime() - 1);
    e = "; expires=" + e.toGMTString();
    document.cookie = CKPrex + n + "=" + escape("") + ";path=/" + e;
}

function set_local(n, v) {
    window.localStorage ? localStorage.setItem(CKPrex + n, v) : set_cookie(n, v);
}

function get_local(n) {
    return window.localStorage ? localStorage.getItem(CKPrex + n) : get_cookie(n);
}

function del_local(n) {
    window.localStorage ? localStorage.removeItem(CKPrex + n) : del_cookie(n);
}
  • 返回顶部
$(document).ready(function() {
    $(window).bind("scroll.back2top", function() {
        var st = $(document).scrollTop(),
            winh = $(window).height();
        (st > 0) ? $('.back2top').show(): $('.back2top').hide();
        if(!window.XMLHttpRequest) {
            $('.back2top').css("top", st + winh - 166);
        } //IE6
    });
    $('.back2top').click(function() {
        $("html, body").animate({
            scrollTop: 0
        }, 200);
    });
});

下面是框架里边的一个跑马灯效果

<html>

    <head>
        <meta charset="UTF-8" />
        <title></title>
        <style type="text/css">
            #site_stats {
                float: right;
                height: 22px;
                overflow: hidden;
                margin: 3px 0 0 0;
                width: 200px;
            }
            
            #site_stats li {
                height: 22px;
                line-height: 22px;
                overflow: hidden;
                text-align: right;
                color: #666666;
                background: url('image/ico_arrow_up.gif') no-repeat right center;
                padding-right: 12px;
            }
            
            #site_stats span {
                color: #38970E;
            }
        </style>

    </head>

    <body>
        <div id="site_stats">
            <ul>
                <li>产品总数:<span>0</span></li>
                <li>求购总数:<span>0</span></li>
                <li>企业总数:<span>1</span></li>
                <li>在线会员:<span>0</span></li>
            </ul>
        </div>
    </body>

</html>
<script type="text/javascript">
    function Dd(i) {
        return document.getElementById(i);
    }

    function dmarquee(lineheight, speed, delay, id) {
        this.t;
        this.p = false;
        this.o = Dd(id);
        this.h = this.o.innerHTML;
        if(this.h.length < 10) return;
        this.o.innerHTML = '<div id="' + id + '_tmp"><div>' + this.h + '</div></div>';
        var h1 = Number(Dd(id).style.height.replace('px', ''));
        var h2 = Dd(id + '_tmp').scrollHeight;
        if(lineheight == -1) return;
        if(h2 * 2 <= h1) {
            this.o.innerHTML = this.h;
            return;
        } else if(h2 >= h1) {
            this.o.innerHTML = this.h + this.h;
        } else {
            this.o.innerHTML = this.h + this.h + this.h;
        }
        this.o.scrollTop = 0;
        var _this = this;
        this.o.onmouseover = function() {
            _this.p = true;
        }
        this.o.onmouseout = function() {
            _this.p = false;
        }
        this.start = function() {
            this.t = setInterval(function() {
                _this.scrolling();
            }, speed);
            if(!this.p) {
                this.o.scrollTop += 1;
            }
        }
        this.scrolling = function() {
            if(this.o.scrollTop % lineheight != 0) {
                this.o.scrollTop += 1;
                if(this.o.scrollTop == h2) this.o.scrollTop = 0;
            } else {
                clearInterval(this.t);
                setTimeout(function() {
                    _this.start();
                }, delay);
            }
        }
        setTimeout(function() {
            _this.start();
        }, delay);
    }
    new dmarquee(22, 10, 3000, 'site_stats')
</script>
效果展示.png

相关文章

网友评论

      本文标题:Destoon框架中的一些JS

      本文链接:https://www.haomeiwen.com/subject/lgkdextx.html