jQuery鼠标悬停图片放大

 时间:2026-02-12 16:08:59

1、新建html文档。

jQuery鼠标悬停图片放大

2、准备好需要用到的图标。

jQuery鼠标悬停图片放大

3、书写hmtl代码。

<div id="aaaa">

<ul>

    <li><img src="lanren01.jpg

        <li><img src="lanren02.jpg

        <li><img src="lanren03.jpg

        <li><img src="lanren04.jpg

    </ul>

</div>

jQuery鼠标悬停图片放大

4、书写css代码。

<style>

*{ margin:0; padding:0; list-style:none;}

img{ border:0;}

body{ background:#000;}

#aaaa{ width:460px; height:auto; margin:150px auto; overflow:hidden;}

#aaaa li{ width:218px; height:155px; overflow:hidden; position:relative; float:left; margin:0 12px 12px 0;}

#aaaa li img{ position:absolute; left:0; top:0; z-index:1; cursor:pointer;}

#aaaa li h2{ font-size:14px; width:198px; font-weight:normal; text-align:left; display:block; position:absolute; left:0; bottom:0; height:30px; line-height:30px; padding:0 10px; background:url(/dot.png) repeat; display:block; z-index:2; color:#444;overflow:hidden; white-space: nowrap;text-overflow: ellipsis;}

</style>

jQuery鼠标悬停图片放大

5、书写并添加js代码。

<script src="jquery.min.js"></script>

<script>

$(function(){

var imgs = $('#aaaa li');

var imgWidth = 218; //图片的默认宽度,主意不要带单位

var imgHeight = 155; //图片的默认高度,主意不要带单位

imgs.hover(function(){

$(this).find('img').stop().animate({

left:'-20',

top:'-20',

right:'-20',

bottom:'-10px',

width:imgWidth+20+'px',

height:imgHeight+20+'px'

},500);

},function(){

$(this).find('img').stop().animate({

left:'0',

top:'0',

right:'0',

bottom:'0',

width:imgWidth+'px',

height:imgHeight+'px'

},500);

});

});

</script>

jQuery鼠标悬停图片放大

6、代码整体结构。

jQuery鼠标悬停图片放大

7、查看效果。

jQuery鼠标悬停图片放大

  • 利用jquery写出鼠标悬停在一张图片上放大图片
  • float居中怎么设置
  • CSS如何实现只显示div的下边框
  • jquery如何改变文字颜色
  • HTML的列表样式
  • 热门搜索
    富春江旅游 澳大利亚 旅游签证 台湾旅游特产 华山旅游路线 六鳌旅游攻略 秦皇岛旅游 普吉岛旅游注意事项 夏天最好的旅游地方 同里旅游攻略 合肥旅游网