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

var $tip, tipItime;

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

    // 插入提示HTML
    $('body').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') {
        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;