/**
 * Created by zw on 2018/01/02.
 * intro 显示大图JS
 */
;(function($){
    $.fn.preview = function(){
        var w = $(window).width();
        var h = $(window).height();
        $(this).each(function(){
            $(this).hover(function(e){
                if(/.png|.gif|.jpg|.bmp|.jpeg/.test($(this).attr("data-bimg"))){
                    $("body").append("<div id='preview'><img src='"+$(this).attr('data-bimg')+"' /></div>");
                }
                var show_x = $(this).offset().left + $(this).width() ;
                var show_y = $(this).offset().top ;
                var scroll_y = $(window).scrollTop();
                $("#preview").css({
                    position:"absolute",
                    padding:"4px",
                    border:"1px solid #f3f3f3",
                    backgroundColor:"#eeeeee",
                    top:show_y + "px",
                    left:show_x + "px",
                    zIndex:1000
                });
                $("#preview > div").css({
                    padding:"5px",
                    backgroundColor:"white",
                    border:"1px solid #cccccc"
                });
                if (show_y + 230 > h + scroll_y) {
                    $("#preview").css("bottom", h - show_y - $(this).height() + "px").css("top", "auto");
                } else {
                    $("#preview").css("top", show_y + "px").css("bottom", "auto");
                }
                $("#preview").fadeIn("fast")
            },function(){
                $("#preview").remove();
            })
        });
    };
})(jQuery);