0

i wan to ask that if my machine got 1000/10000 of image and each image is named follow by order (1.jpg, 2.jpg, 3.jpg, 4.jpg .... 10000.jpg) , how to do it to let it display follow th order ?

i saw a lot of question on internet that they put it on the JLabel but many of them say it won't work . i have even try a few method to let it display like javascript but it is not the result i want.

I wish the program is running like 0.5 seconds a time and display the image followed the image number.

Can anyone guild me through this ? thanks in advance

==================================================================================

update : this is my javascript code

<html> 
<head>
</head>

<body>
<img src="images/image1.jpg" alt="rotating image" width="600" height="500" id="rotator">

<script type="text/javascript">
(function() {
var rotator = document.getElementById('rotator');  // change to match image ID
//var imageDir = 'images/';                          // change to match images folder
var delayInSeconds = 1;                            // set number of seconds delay
// list image names
var images = ['1.jpg','2.jpg', '3.jpg', '4.jpg'];

// don't change below this line
var num = 0;
var changeImage = function() {
    var len = images.length;
    rotator.src = images[num++];
    if (num == len) {
        num = 0;
    }
};
setInterval(changeImage, delayInSeconds * 50);
})();
</script>
</body>
</html>
4

1 回答 1

0

首先,您需要预先加载图像,为此,您可以将它们添加到隐藏的 div 中。然后用它替换你的原始图像。像这样的东西:

<html>
<head>
<title>ViewImage</title>
<script type="text/javascript" src="/jquery-1.4.2.min.js"></script>

<script>
var img_num = 1;
$(function(){
window.setInterval(function(){
    var img = $('#hiden-img');
    if(img[0].complete==true)
        $('#real-image').attr('src', img.attr('src'));
    img_num++;
    if(img_num>10000)img_num=1;
    img.attr('src', '/img/'+img_num+'.jpg');

}, 500);
});
</script>
</head>
<body>
<img id="hiden-img" style="display:none;"/>
<img id="real-image" src="/img/1.jpg"/>
</body>
</html>

像这样试试。下载 jquery 并将其放置在您的站点中,将路径“/path/to/img”(2 次)和“/path/to/jquery”替换为您的真实路径。这应该可以解决问题。

您不需要每秒刷新页面。您不需要全部刷新。它适用于我的网站。

于 2012-05-14T07:52:59.900 回答