JQuery鼠标移动上去显示预览图


body中:

 <img src="../images/icon_view.gif" bigimg="../img.jpg" title="查看预览图" class="imgtip" />
<script type="text/javascript">
    //放大图片
    $(function () {
        var x = 10;
        var y = 20;
        $(".imgtip").mouseover(function (e) {
            this.myTitle = this.title;
            this.title = "";
            var imgtip = "<div id='imgtip'><img src='" + $(this).attr("bigimg") + "' width='300' alt='预览图'/><\/div>"; //创建 div 元素
            $("body").append(imgtip); //把它追加到文档中                         
            $("#imgtip")
                .css({
                    "top": (e.pageY + y) + "px",
                    "left": (e.pageX + x) + "px"
                }).show("fast");   //设置x坐标和y坐标,并且显示
        }).mouseout(function () {
            this.title = this.myTitle;
            $("#imgtip").remove();  //移除 
        }).mousemove(function (e) {
            $("#imgtip")
                .css({
                    "top": (e.pageY + y) + "px",
                    "left": (e.pageX + x) + "px"
                });
        });
    });
</script>

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM