jquery實現(xiàn)鼠標滑過小圖時顯示大圖的方法

字號:


    這篇文章主要介紹了jquery實現(xiàn)鼠標滑過小圖時顯示大圖的方法,涉及圖片及鼠標操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
    本文實例講述了jquery實現(xiàn)鼠標滑過小圖時顯示大圖的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
    代碼如下:
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8" />
    <title></title>
    </head>
    <style type="text/css">
    li{list-style:none;float:left;margin-left:10px;}
    </style>
    <script type="text/javascript" src="jquery-1.8.2.min.js"></script>
    <script type="text/javascript">
    var data = {
    "images/11_s.jpg":["images/11_b.jpg","美人1"],
    "images/22_s.jpg":["images/22_b.jpg","美人2"],
    "images/33_s.jpg":["images/33_b.jpg","美人3"],
    "images/44_s.jpg":["images/44_b.jpg","美人4"]
    };
    $(function(){
    $.each(data,function(key,value){
    //初始化最后一個div為隱藏
    $("div").last().hide();
    //創(chuàng)建小圖的節(jié)點
    var smallPath = $("<img src='" + key + "' />").css({"margin":"5px","padding":"2px","border":"1px solid #000"});
    //設置大圖地址和名稱
    bigImgPath = smallPath.attr("bigMapPath",value[0]);
    bigImgName = smallPath.attr("bigMapName",value[1]);
    $("div").first().append(smallPath);
    //小圖上添加事件
    smallPath.mouseover(function(){
    //最后一個div淡入效果
    $("div").last().fadeIn("fast");
    //獲取大圖地址
    $("#show").attr("src",$(this).attr("bigMapPath"));
    //獲取大圖名稱并設置樣式
    $("#imgTitle").text($(this).attr("bigMapName")).css({"background":"#ebf1de","padding":"10px","margin-bottom":"10px"});
    });
    smallPath.mouseout(function(){
    $("div").last().fadeOut("fast");
    });
    });
    });
    </script>
    <body>
    <div></div>
    <div>
    <img id="show" src="" />
    </div>
    </body>
    </html>