js实现将图片裁切成方形显示,鼠标移入放大效果
2014-12-03 13:42
1006 查看
Dome下载 效果如图:
css:
#clip { width: 306px; zoom: 1; }
#clip:after {
content: "";
display: block;
height: 0;
clear: both;
}
#clip li {
float: left;
width: 100px;
height: 100px;
margin: 1px;
position: relative;
_display: inline;
}
#clip li .small_img {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
}
html:
<ul id="clip">
<li><div class="small_img"><a href="#"><img
src="images/1.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/2.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/3.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/4.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/5.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/6.jpg" alt=""></a></div></li>
</ul>
javascript:
<script type="text/javascript" src="script/jquery-1.8.3.min.js"></script>
<script>
$(function () {
$("#clip>li").each(function () {
var $this = $(this).find("img");
var width = $this.width();
var height = $this.height();
var newWidth,newHeight;
if (width > height) {
newWidth = width / (height / 100);
$this.css({
"position": "absolute",
"top": "0",
"left": "50%",
"margin-left": parseInt(-newWidth/2) + "px",
"height": "100px"
});
}
else if (width == height) {
$this.css({
"width": "100px"
});
}
else {
newHeight = height / (width / 100);
$this.css({
"position": "absolute",
"top": "50%",
"left": "0",
"margin-top": parseInt(-newHeight/2) + "px",
"width": "100px"
});
}
var newImg = $this.clone();
$(this).hover(
function () {
$(this).append(newImg.removeAttr("style"));
newImg.css({
"width": "202px",
"position": "absolute",
"top": "0",
"left": "0",
"z-index": "10",
"display": "none"
}).show("fast");
},
function () {
newImg.hide("fast",function () {$(this).remove()});
}
)
});
})
</script>
css:
#clip { width: 306px; zoom: 1; }
#clip:after {
content: "";
display: block;
height: 0;
clear: both;
}
#clip li {
float: left;
width: 100px;
height: 100px;
margin: 1px;
position: relative;
_display: inline;
}
#clip li .small_img {
width: 100px;
height: 100px;
position: relative;
overflow: hidden;
}
html:
<ul id="clip">
<li><div class="small_img"><a href="#"><img
src="images/1.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/2.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/3.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/4.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/5.jpg" alt=""></a></div></li>
<li><div class="small_img"><a href="#"><img
src="images/6.jpg" alt=""></a></div></li>
</ul>
javascript:
<script type="text/javascript" src="script/jquery-1.8.3.min.js"></script>
<script>
$(function () {
$("#clip>li").each(function () {
var $this = $(this).find("img");
var width = $this.width();
var height = $this.height();
var newWidth,newHeight;
if (width > height) {
newWidth = width / (height / 100);
$this.css({
"position": "absolute",
"top": "0",
"left": "50%",
"margin-left": parseInt(-newWidth/2) + "px",
"height": "100px"
});
}
else if (width == height) {
$this.css({
"width": "100px"
});
}
else {
newHeight = height / (width / 100);
$this.css({
"position": "absolute",
"top": "50%",
"left": "0",
"margin-top": parseInt(-newHeight/2) + "px",
"width": "100px"
});
}
var newImg = $this.clone();
$(this).hover(
function () {
$(this).append(newImg.removeAttr("style"));
newImg.css({
"width": "202px",
"position": "absolute",
"top": "0",
"left": "0",
"z-index": "10",
"display": "none"
}).show("fast");
},
function () {
newImg.hide("fast",function () {$(this).remove()});
}
)
});
})
</script>
相关文章推荐
- JS实现鼠标移动到缩略图显示大图的图片放大效果
- JS实现鼠标移动到缩略图显示大图的图片放大效果
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)(2)
- css3实现鼠标移入图片放大效果
- js实现鼠标的移入移出控制图片的明暗显示
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)(1)
- js实现图片显示局部,鼠标经过显示全部的效果
- JS实现 鼠标放上去 图片自动放大的效果
- 原生JS实现鼠标悬停图片显示文字效果
- JS与CSS3实现图片响应鼠标移动放大效果示例
- mm_menu.js(实现鼠标移入横向显示二级菜单效果)
- js实现图片显示局部,鼠标经过显示全部的效果
- js实现图片显示局部,鼠标经过显示全部的效果
- JS实现鼠标移入移出控制图片的切换效果
- JS 实现鼠标指向图片时图片放大的效果
- JS实现鼠标滑过图片的抖动效果
- js实现简单的单击图片放大功能---仿新浪微博图片放大效果
- Jquery实现鼠标放在图片上面显示大图效果
- 鼠标滑上去后图片放大浮出效果的实现
- 非常惊艳的Css3的桌面上散落的相片效果,以及单击放大图片的LightBox效果(独立Js非jQuery)的实现原理