【发布时间】:2011-12-20 18:21:45
【问题描述】:
我已经使用 javascript 创建了一个简单的图像旋转器,但使用“旧浏览器”(例如 IE 6、7 和 8)速度很慢。我认为图像将首先加载,然后启动旋转器。. 一些让它更快的提示?
为什么我自己创建了一个旋转器?我发现的所有旋转器都剪切(裁剪)了图像。我需要完整的图像...必要时在左/右或上/下留一些空白。
Javascript 部分:
//Loop through pictures
var tid = setInterval(mycode, 3000);
function mycode() {
if($.random(0,1) == 1){
//Fade
$('#alleplaatjes img.active').fadeOut(500,function(){
$(this).removeClass();
if($(this).next().length == 0){
$('#alleplaatjes img').first().fadeIn(500);
$('#alleplaatjes img').first().addClass('active');
} else {
$(this).next().fadeIn(500);
$(this).next().addClass('active');
}
});
} else {
//Slide
$('#alleplaatjes img.active').slideUp(500,function(){
$(this).removeClass();
if($(this).next().length == 0){
$('#alleplaatjes img').first().slideDown(500);
$('#alleplaatjes img').first().addClass('active');
} else {
$(this).next().slideDown(500);
$(this).next().addClass('active');
}
});
}
};
PHP部分:
<?php
$dir = "/home/zwuq/domains/***/public_html/afbeelding/";
foreach(glob($dir."*") as $file){
$afbeelding = 'afbeelding/'.str_replace($dir, '', $file);
$toevoeging = FALSE;
if(!$eerste_plaatje){
$toevoeging = ' class="active"';
$eerste_plaatje = $afbeelding;
}
$plaatjes .= '<img'.$toevoeging.' src="'.$afbeelding.'" style="max-width: 99%; max-height: 99%;">';
}
?>
HTML 部分:
<div id="alleplaatjes" style="width:100%; height:100%; margin:0px; padding:0px; z-index:1; text-align: center;">
<? echo $plaatjes; ?>
</div>
【问题讨论】:
-
定义“旧浏览器”?
-
您的意思是旧版浏览器,还是使用旧版浏览器的旧电脑?
-
刚刚添加 :) 例如 IE6、7 和 8
-
我也可以编写在较新的浏览器中非常缓慢的图像旋转。这没什么大不了的。您可能对网络浏览器期望过高。使用代码,而不是光滑的效果。如果您检测到它是一个快速浏览器,您可以添加它们,这样每个人都可以使用您的网站。
-
cut the images这是否意味着裁剪?还是您指的是一些如何执行转换?
标签: php javascript jquery html rotator