我有一个divs和一个jQuery UI滑块内的图像列表,当用户滑动图像应该调整大小/缩放(无论你想调用它),我试图选择所有的图像和改变CSS的宽度和高度使用jquery。它可以工作,但是非常缓慢而且不流畅。使用Javascript缩放/缩放多个图像的最佳方式?
我读过浏览器吸取调整大小的图像,但应该有一种方法来提高性能或流动,至少与正在加载的图像。
这里是我的HTML标记:
<div class="file-list">
<div class="file-cell">
<div class="thumb-wrapper">
<img width="100" height="100" title="mytitle" alt="myalt" src="image1.jpg">
</div>
</div>
<div class="file-cell">
<div class="thumb-wrapper">
<img width="100" height="100" title="mytitle" alt="myalt" src="image1.jpg">
</div>
</div>
</div>
这里是CSS代码:
div.file-cell {
margin: 10px;
float: left;
padding: 8px;
width: 100px;
background: none;
margin-bottom: 5px;
cursor: pointer;
}
下面是Javascript代码:
jQuery().ready(function(){
var images = jQuery('.thumb-wrapper img'); //caches the query when dom is ready
jQuery("#slider").slider({
step: 13,
min: 70,
max: 200,
value: 100,
slide: function(event, ui){
//i think if i return while resizing increases performace,
//confirm this please
if(resizing)
return;
resizing = true;
var size = CELL_WIDTH * ui.value/100;
size = size + 'em';
images.css({
'width': size,
'height': size
});
resizing = false;
}
});
}
注:我应该删除图像的宽度和高度属性?他们在那里,因为他们由wordpress产生。
谢谢!有效!在过去的几天里,我一直在为此苦苦挣扎。我有点新来的JavaScript,所以我怀疑resize变量不工作。 – Skatox 2012-03-31 16:24:03