need jQuery help: randomized images and loading script
Page 1 of 1
Lutzifer
Modzilla



Posts: 12740
Location: ____________________ **** vegan zombie **** GRRAAIIINNSS _______
PostPosted: Tue, 3rd Nov 2009 00:01    Post subject: need jQuery help: randomized images and loading script
i m trying to merge two nice scripts together but somehow i m making something wrong =(

This is how i thought it should work:
Code:

    $(function () {
       var randomImages = ['./content/pp/img/2511_1_b.jpg','./content/pp/img/5178_1_b.jpg','./content/kameha/img/5744_1_b.jpg'];
      var rndNum = Math.ceil(Math.random() * randomImages.length);
        var img = new Image();
        $(img).load(function () {
            $(this).hide();
            $('#loader').removeClass('loading').append(this);
            $(this).fadeIn();
        }).error(function () {
            // notify the user that the image could not be loaded
        }).attr('src', '+ rndNum +' );
    });


Derived from:
http://jqueryfordesigners.com/image-loading/
and:
http://www.designateonline.com/discussions/comments.php?DiscussionID=4258&page=1
Back to top
Lutzifer
Modzilla



Posts: 12740
Location: ____________________ **** vegan zombie **** GRRAAIIINNSS _______
PostPosted: Tue, 3rd Nov 2009 00:05    Post subject:
it works as it should when i leave out the randomize function. So how do i go about adding the array of random pics in there without fucking it up?
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Tue, 3rd Nov 2009 01:46    Post subject:
oh ok Very Happy

> }).attr('src', '+ rndNum +' ); <

look closely ....

yeah ...

}).attr('src', rndNum );

^^ should do the trick, cause the rest looks ok Wink

I haven't tried it myself. If it doesn't work just post again and I'll take a deeper look Wink


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Lutzifer
Modzilla



Posts: 12740
Location: ____________________ **** vegan zombie **** GRRAAIIINNSS _______
PostPosted: Tue, 3rd Nov 2009 20:04    Post subject:
nope =(
Back to top
silent2




Posts: 20

PostPosted: Wed, 4th Nov 2009 12:08    Post subject: Re: need jQuery help: randomized images and loading script
Maybe then it works like this:
}).attr('src', randomImages[rndNum] );
(You know... number isn't exactly the source.)
?
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Wed, 4th Nov 2009 12:26    Post subject:
Sorry to hijack the thread, but I have a question. I have regular HTML page with images, but I saw on some tutorial cool java thing where you can make sth like this http://cssglobe.com/lab/tooltip/02/

Can I just implement it in the existing layout?


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
garus
VIP Member



Posts: 34200

PostPosted: Wed, 4th Nov 2009 12:37    Post subject:
snip


Last edited by garus on Tue, 27th Aug 2024 21:14; edited 1 time in total
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Wed, 4th Nov 2009 12:41    Post subject:
Laughing

Well thnx for the heads up Very Happy

So I just find the matching code and put it in my page?


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
silent2




Posts: 20

PostPosted: Wed, 4th Nov 2009 16:13    Post subject:
Yep, pretty much. Look under main.js in page source.
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Wed, 4th Nov 2009 17:02    Post subject:
woohoo!! Very Happy Thnx!!

EDIT: I have a problem :\

I have done as it said in the tutorial page, but I don't have little images which turn to big, I have Big images when rolled over give the same - big image... Plus I think that their main.js is not liking my style.css Sad Halp!

The jscript code is:

 Spoiler:
 


And mine is:
 Spoiler:
 


I have already put the images and jquery.js but it's not working as I would wish...


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
Lutzifer
Modzilla



Posts: 12740
Location: ____________________ **** vegan zombie **** GRRAAIIINNSS _______
PostPosted: Wed, 4th Nov 2009 20:56    Post subject: Re: need jQuery help: randomized images and loading script
silent2 wrote:
Maybe then it works like this:
}).attr('src', randomImages[rndNum] );
(You know... number isn't exactly the source.)
?


yeah, now it works! Had it like that before and it didnt work because i put it in ' '

The only thing odd now is, that it only works for two of the three test-images. I ll have to look into that now =)

thanx for reminding me, would have given up now otherwise Very Happy
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Wed, 4th Nov 2009 21:15    Post subject:
You should use Math.floor(Math.random() * randomImages.length);

cause random goes from 0 to <1.


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
Lutzifer
Modzilla



Posts: 12740
Location: ____________________ **** vegan zombie **** GRRAAIIINNSS _______
PostPosted: Wed, 4th Nov 2009 21:20    Post subject:
PumpAction wrote:
You should use Math.floor(Math.random() * randomImages.length);

cause random goes from 0 to <1.


yeah, came up with that by myself already and everything is working great now. Thanx for helping! <3 <3 <3
Back to top
PumpAction
[Schmadmin]



Posts: 26759

PostPosted: Wed, 4th Nov 2009 21:22    Post subject:
no problem Smile


=> NFOrce GIF plugin <= - Ryzen 3800X, 16GB DDR4-3200, Sapphire 5700XT Pulse
Back to top
silent2




Posts: 20

PostPosted: Thu, 5th Nov 2009 10:48    Post subject:
dingo_d wrote:

EDIT: I have a problem :\

I have done as it said in the tutorial page, but I don't have little images which turn to big, I have Big images when rolled over give the same - big image... Plus I think that their main.js is not liking my style.css Sad Halp!

I have already put the images and jquery.js but it's not working as I would wish...


Well they do have 2 different images in code
Code:

<li><a href="3.jpg" class="preview"><img src="3s.jpg" alt="gallery thumbnail" /></a></li>

There is a 3.jpg and 3s.jpg, which probably means 3.jpg small and big version. So yes, you actually have to create thumbnails or specify image size in img tag to have smaller thumbnails.
Back to top
dingo_d
VIP Member



Posts: 14555

PostPosted: Thu, 5th Nov 2009 10:54    Post subject:
Oh jea I didn't see that! Thnx Very Happy


"Quantum mechanics is actually, contrary to it's reputation, unbeliveably simple, once you take the physics out."
Scott Aaronson
chiv wrote:
thats true you know. newton didnt discover gravity. the apple told him about it, and then he killed it. the core was never found.

Back to top
silent2




Posts: 20

PostPosted: Thu, 5th Nov 2009 13:56    Post subject:
Happy to help. Smile
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group