修改缩略图脚本中的放大图像,以根据其大小属性动态显示图像
modifying an enlargement image from thumbnail script to dynamically display image based on their size property
我试图修改这个简单的js脚本,无论何时点击缩略图都会放大图像。问题是,放大的图像是根据定义的固定宽度显示的。我想放大的图像显示根据它的大小属性。例如,一个图像的宽度为200,高度为300,我希望该图像显示根据该大小,而不是固定的300的高度和宽度。
我一直在尝试解决方案,如删除宽度,但相反,图像被放大到全屏尺寸。
我如何修改这个脚本,使放大的图像显示根据它的原始大小属性
剧本属于roXon,我给他充分的信任如何放大图像从缩略图在jQuery?
这是jquery http://jsbin.com/egevij/3/edit
HTML<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<link rel="stylesheet" href="css/forms.css">
<meta charset=utf-8 />
<title>Demo by roXon</title>
</head>
<body>
<div id="jQ_popup_window">
<div id="jQ_popup" class="shadow radius">
<div id="jQ_popup_close"></div>
</div>
</div>
<img src="http://placehold.it/250x150/cf5" data-full="1.jpg" alt="" />
<img src="http://placehold.it/250x150/fof" data-full="http://placehold.it/860x590/fof" alt="" />
<script type = "text/javascript" src ="trouble.js"></script>
</body>
</html>
jQuery: // POPUP WINDOW:
var scrT = $(window).scrollTop();
$(window).scroll(function(){
scrT = $(window).scrollTop();
});
// GET and use WINDOW HEIGHT //
$.getDocHeight = function(){
var D = document;
return Math.max(Math.max(D.body.scrollHeight, D.documentElement.scrollHeight), Math.max(D.body.offsetHeight, D.documentElement.offsetHeight), Math.max(D.body.clientHeight, D.documentElement.clientHeight));
};
// POPUP WINDOW (lightbox for video and other)
// GET WINDOW SCROLLtop OFFSET
$('[data-full]').on('click', function(e){
e.preventDefault();
$('#jQ_popup').css({
top: scrT+15
}).find('img').remove();
$('#jQ_popup_window').height($.getDocHeight).fadeTo(0,0).css({
marginLeft:0
}).fadeTo(600,1);
var imgToLoad = $(this).data('full');
$('<img>', {src:imgToLoad, width:'100%'}).appendTo('#jQ_popup');
});
// close popup
$('#jQ_popup_close, #jQ_popup_window').on('click', function(){
$('#jQ_popup_window').fadeTo(600,0,function(){
$(this).hide();
});
});
$('#jQ_popup').on('click', function(ev){
ev.stopPropagation();
});
// end POPUP WINDOW
CSS: /* === POPUP WINDOW === */
#jQ_popup_window{
background: rgba(0,0,0,0.6);
left: 0;
margin-left: -9000px;
position: absolute;
top: 0;
width: 100%;
z-index:999999;
}
#jQ_popup {
background: #000;
border: 1px solid #BDB9B8;
margin: 30px auto;
padding: 25px;
position: relative;
width: 600px; /* SET HERE DESIRED W .*/
}
#jQ_popup_close {
background:#fff;
cursor: pointer;
height: 28px;
width: 28px;
position: absolute;
z-index:999999;
right: 10px;
top: 10px;
-webkit-border-radius:30px;
border-radius:30px;
border:2px solid #fff;
border-color: rgba(255,255,255,0.2);
}
#jQ_popup_close:hover{
background:#f00;
}
/* #POPUP WINDOW */
像这样的东西应该可以工作
<img src="http://placehold.it/250x150/fof" data-full="http://placehold.it/860x590/fof" data-width="860px" data-height="590px" alt="" />
$('<img>', {src:imgToLoad, width: $(this).data('width'),height: $(this).data('height')}).appendTo('#jQ_popup');
或者这个取路径/860x590/
的大小var dimensions=$(this).data('full').match(/('d+)x('d+)/);
$('<img>', {src:imgToLoad, width: dimensions[1]+'px',height: dimensions[2]+'px'}).appendTo('#jQ_popup');
相关文章:
- nodejs-expressjs上传图像并显示它们
- 画廊图像未显示
- 动态显示JSON文件内容
- 可单击滚动图像以显示文本框
- 背景图像前显示Javascript警报
- 如何将(a*b)两个输入文本值相乘,并在javascript中随文本变化动态显示
- Highcharts:根据表单输入动态显示数据
- ImageMapster可以动态显示和隐藏图像选择崩溃
- AngularJS动态显示多条记录
- 在图像上显示菜单
- Wordpress cforms插件CAPTCHA图像未显示
- 当我悬停使用php连接到mysql的图像时显示标题
- HTML 图像未显示
- 使用 Node.js 和 socket.io 和 fs 动态显示图像
- 用JavaScript在html表中动态显示图像
- 在动态显示的图像上设置下载属性
- jQuery卷轴插件:动态显示或隐藏卷轴图像
- 如何在ASP中动态显示图像.. NET文字控制
- 修改缩略图脚本中的放大图像,以根据其大小属性动态显示图像
- 动态设置背景图像不显示在Chrome