javascript代码实例教程-jQuery实现鼠标划过展示大图的方法教程

发布时间:2019-01-01 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了javascript代码实例教程-jQuery实现鼠标划过展示大图的方法教程脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。

本文实例讲述了jQuery实现鼠标划过展示大图的方法。分享给大家供大家参考。具体如下:

这里用css和jquery实现鼠标移上元素时大图展示,并且大图不能溢出整个p框

代码如下:

<!DOCTYPE htML PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="http://www.w3.org/1999/xhtml">
<head>
<;meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery鼠标划过展示大图</title>
<style type="text/css">
* { margin:0; padding:0; }
body { font:12px/1.5 tahoma, arial, simsun; }
.wrap { position:relative; margin:0 auto; width:319px; height:243px; }
table { border-collapse:collapse; border-spacing:0; }
td { border:1px solid #ccc; background:#f0f0f0; width:80px; height:80px; }
td p { position:relative; width:100%; height:100%; background:#eee; }
td b { display:block; position:relative; z-index:20; width:20px; height:20px; background:#fff; }
td a.s { display:block; position:absolute; z-index:10; left:0; top:0; height:100%; width:100%; text-indent:-999em; overflow:hidden; background:url(Images/nb/8080LOGo.jpg) no-repeat; }
#hideBox { display:none; position:absolute; width:140px; height:120px; background:#fff; border:1px solid #333; z-index:300; }
#hideBox a { display:block; height:100%; width:100%; }
</style>
<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>&nbsp;
<script type="text/javascript">
    $(document).ready(function(){  
        VAR wrapWidth = $(".wrap").width();
        var wrapHeight = $(".wrap").height();
        var boxWidth = $("#hideBox").outerWidth();
        var boxHeight = $("#hideBox").outerHeight();       
        $("td a").mouseover(function(){    
            var pos = $(this).parent("p").position();
            var toLeft = wrapWidth - (boxWidth + pos.left);
            var toTop = wrapHeight - (boxHeight + pos.top);
            if(toLeft>0){
                    $("#hideBox").css({left:pos.left});
            }
            else if(toLeft<0){
                    $("#hideBox").css({left:wrapWidth-boxWidth});
            }
            if(toTop>0){
                    $("#hideBox").css({top:pos.top});
            }
            else if(toTop<0){
                    $("#hideBox").css({top:wrapHeight-boxHeight});
            }          
            $("#hideBox").show();          
        });
        $("#hideBox").mouseout(function(){
            $(this).hide();
        });    
    });
</script>
</head>
<body>
<p class="wrap">
    <table>
        <tr>
            <td><p><b>15</b><a id="g1" class="s" href="#">名称1</a></p></td>
            <td><p><b>16</b><a id="g2" href="#">名称2</a><br />
                    <a id="g3" href="#">名称3</a></p></td>
            <td><p><b>15</b><a id="g3" class="s" href="#">名称1</a></p></td>
            <td><p><b>15</b><a id="g4" class="s" href="#">名称1</a></p></td>
        </tr>
        <tr>
            <td><p><b>15</b><a id="g5" class="s" href="#">名称1</a></p></td>
            <td><p><b>15</b><a id="g6" class="s" href="#">名称1</a></p></td>
            <td><p><b>16</b><a id="g7" href="#">名称2</a><br />
                    <a id="g8" href="#">名称3</a></p></td>
            <td><p><b>16</b><a id="g9" href="#">名称2</a><br />
                    <a id="g3" href="#">名称3</a></p></td>
        </tr>
        <tr>
            <td><p><b>16</b><a id="g11" href="#">名称2</a><br />
                    <a id="g12" href="#">名称3</a></p></td>
            <td><p><b>16</b><a id="g13" href="#">名称2</a><br />
                    <a id="g14" href="#">名称3</a></p></td>
            <td><p><b>15</b><a id="g15" class="s" href="#">名称1</a></p></td>
            <td><p><b>15</b><a id="g16" class="s" href="#">名称1</a></p></td>
        </tr>
    </table>
    <p id="hideBox"><a href="">大图展示</a></p>
</p>
</body>
</html>

希望本文所述对大家的jQuery程序设计有所帮助。

觉得可用,就经常来吧! 脚本宝典 欢迎评论哦! js脚本,巧夺天工,精雕玉琢。小宝典献丑了!

脚本宝典总结

以上是脚本宝典为你收集整理的javascript代码实例教程-jQuery实现鼠标划过展示大图的方法教程全部内容,希望文章能够帮你解决javascript代码实例教程-jQuery实现鼠标划过展示大图的方法教程所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。