tip.js 877 Bytes
/**
 * 弹框提示
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2015/10/10
 */
var $ = require('jquery');

var $tip, tipItime;

/**
 * 初始化提示框
 */
(function() {
    var tipHtml = '<div id="yoho-tip" class="yoho-tip"></div>';

    //插入提示HTML
    $('.yoho-page').append(tipHtml);

    $tip = $('#yoho-tip');
    $tip.on('touchend', function() {
        $tip.hide();

        //清除Timeout
        clearTimeout(tipItime);
    });
}());

/**
 * 显示提示
 */
function show(con, dur) {
    var content, duration;

    if (typeof con === 'undefined' || con === '') {
        return;
    }

    content = con.toString();
    duration = (dur && dur > 0) ? dur : 2000;

    $tip.text(content).show();

    tipItime = setTimeout(function() {
        if ($tip.css('display') === 'block') {
            $tip.hide();
        }
    }, duration);
}

exports.show = show;