Guest User

Untitled

a guest
Apr 22nd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. //Loop through the images and print them to the page
  2. for (var i=0; i < totalBoxes; i++){
  3. //$("p").add(arr).appendTo('#bg');
  4. $.ajax({
  5. url: "random.php?no=",
  6. cache: false,
  7. success: function(html){
  8. $(html).fadeIn(html).appendTo('#bg');
  9. }
  10. });
  11. }
  12.  
  13. //Choose the image to be faded in
  14. $(".pf-box img").hover(function(){
  15. var largePath = $(this).attr("rel");
  16. $(this).fadeOut("slow", function() {
  17. $(this).attr({ src: largePath }).fadeIn("slow");
  18. });
  19. return false;
  20. });
  21.  
  22. <div class="pf-box" style="">
  23. <a href="#">
  24. This is where the image is printed with the rel attribute on the image tag. (stackoverflow didnt allow the posting of the img tag because its my first post)
  25. </a>
  26. </div>
  27.  
  28. function(html) {
  29. $('#bg').append(html).fadeIn('slow');
  30. }
  31.  
  32. // Loop through the images and print them to the page.
  33. // Attach hover event within the callback, after image has been added.
  34. for (var i=0; i < totalBoxes; i++){
  35. $.ajax({
  36. url: "random.php?no=",
  37. cache: false,
  38. success: function(html) {
  39. // following line I originally suggested, but let's make it better...
  40. //$('#bg').append(html).fadeIn('slow');
  41. // also note the fine difference between append and appendTo.
  42. var $d = $(html).hide().appendTo('#bg').fadeIn('slow');
  43. $('img', $d).hover(function() {
  44. var largePath = $(this).attr("rel");
  45. $(this).fadeOut("slow", function() {
  46. $(this).attr({ src: largePath }).fadeIn("slow");
  47. });
  48. });
  49. }
  50. });
  51. }
  52.  
  53. success: function(html){
  54. $(html).appendTo('#bg').fadeIn("slow");
  55. }
Add Comment
Please, Sign In to add comment