首页 > web前端 > js教程 > 正文

一个支持任意尺寸的图片上下左右滑动效果_jquery

php中文网
发布: 2016-05-16 16:38:46
原创
1610人浏览过

常常遇到图片通过后台上传后就变形了的问题,如果你的网站风格适合,可以用这种方式来给页面布局,支持任意尺寸的图片滑动(上下左右滑动)

萝卜简历
萝卜简历

免费在线AI简历制作工具,帮助求职者轻松完成简历制作。

萝卜简历 171
查看详情 萝卜简历
<! DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>任意尺寸的图片滑动</title>
<style>
div { margin: 0 auto; overflow: hidden;}
.main { width: 1000px;}
.divimg_div1 { width: 380px; float: left;}
.divimg .div4_title { width: 380px; height: 103px; background-color: #EDB205; color: #FFF; font-family: "微软雅黑"; font-size: 22px; font-weight: bold; line-height: 90px; text-align: center; letter-spacing: 5px;}
.divimg_img1 { width: 380px; height: 414px; margin-top: 5px; background-color: #FFF; position: relative;}
.divimg_div2 { width: 615px; float: right;}
.divimg_img2 { width: 194px; height: 256px; float: left; background-color: #FFF; position: relative;}
.divimg_img3 { width: 417px; height: 256px; float: right; background-color: #FFF; position: relative;}
.divimg_img4 { width: 366px; height: 262px; float: left; margin-top: 4px; background-color: #FFF; position: relative;}
.divimg_img5 { width: 245px; height: 262px; float: right; margin-top: 4px; background-color: #FFF; position: relative;}
.divimg .gif { position: absolute; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px; z-index: 2;}
.divimg .img { position: absolute; z-index: 1; left: 0; top: 0; display: none;}
</style>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function(e) {
$(".divimg .img").load(function(){
var w=parseInt($(this).width());
var h=parseInt($(this).height());
var hh=$(this).parent().height();
var ww=$(this).parent().width();
var blw=w/parseInt(ww);
var blh=h/parseInt(hh);
function left(){
$(this).animate({left:-(parseInt(parseInt(hh)/h*w)-(parseInt(ww)))},10000,right)
}
function right(){
$(this).animate({left:0},10000,left);
}
function top(){
$(this).animate({top:-(parseInt(parseInt(ww)/w*h)-(parseInt(hh)))},10000,bottom);
}
function bottom(){
$(this).animate({top:0},10000,top);
}
if(blw > blh)
{
$(this).height(hh).width(parseInt(parseInt(hh)/h*w));
$(this).prev().hide(); 
$(this).css({"z-index":"3","display":"block"}); 
$(this).animate({left:-(parseInt(parseInt(hh)/h*w)-(parseInt(ww)))},10000,right);
}
else if(blw < blh)
{
$(this).height(parseInt(parseInt(ww)/w*h)).width(ww);
$(this).prev().hide();
$(this).css({"z-index":"3","display":"block"});
$(this).animate({top:-(parseInt(parseInt(ww)/w*h)-(parseInt(hh)))},10000,bottom);
}
});
$(".div4 .img").each(function(index, element) {
$(this).attr("src",$(this).attr("name"));
});
}); 
</script>
</head>
<body>
<div class="main">
<div class="divimg">
<div class="divimg_div1">
<div class="divimg_title">任意尺寸的图片滑动</div>
<div class="divimg_img1"> <img  class="gif" src="images/loadding.gif"    style="max-width:90%"  style="max-width:90%" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > <img  class="img" name="images/am_bigimg01.jpg" src="" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > </div>
</div>
<div class="divimg_div2">
<div class="divimg_img2"> <img  class="gif" src="images/loadding.gif"    style="max-width:90%"  style="max-width:90%" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > <img  class="img" name="images/am_nyimg01.jpg" src="" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > </div>
<div class="divimg_img3"> <img  class="gif" src="images/loadding.gif"    style="max-width:90%"  style="max-width:90%" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > <img  class="img" name="images/am_img02.jpg" src="" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > </div>
<div class="divimg_img4"> <img  class="gif" src="images/loadding.gif"    style="max-width:90%"  style="max-width:90%" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > <img  class="img" name="images/am_newimg01.jpg" src="" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > </div>
<div class="divimg_img5"> <img  class="gif" src="images/loadding.gif"    style="max-width:90%"  style="max-width:90%" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > <img  class="img" name="images/am_rynewimg03.jpg" src="" / alt="一个支持任意尺寸的图片上下左右滑动效果_jquery" > </div>
</div>
</div>
</div>
</body>
</html>
登录后复制
最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号