JQuery - Preloading Images


Joined
Apr 1, 2019
Messages
2
Reaction score
0
Ok, my JQuery assignment requires preloading images. I'm using Netbeans and tried several JQuery tutorials, but the code below is still not preloading the images--it always instead loads the image directly. JQuery Code's below, followed by the HTML provided for this assignment, and I'm using Netbeans.

JavaScript:
```
$("document").ready(function() {
 
    var pics =[
        ["images/casting1.jpg"]
        ["images/casting2.jpg"]
        ["images/catchrelease.jpg"]
        ["images/fish.jpg"]
        ["images/lures.jpg"]
    ];
    var count = pics.length;
    var cur = 1;
 
    $("#image_list a").each(function(){
        var tempimage = new Image();
        //var imageURL = $(this).attr("href");
        tempimage.src = $(this).attr("href");
    });
 
 
    //preload images
    var $img = new Array();
    for(var i=0;i<count-1;i++){
        var $image = $("<img>").attr("src",pics[0]);
        $imgs.push($('<img>').attr('src', pics[0]));
    }
 
    $("#pics_holder").append("<li>");
    $("#pics_holder li").css("width",(count)*990);

    for(var i=0;i<count-1;i++) {
    var $li = $("<li>").append($imgs);
    $("#pics_holder li").append($li);
}
 
    $("#image_list a").click(function(evt){
        var imageURL = $(this).attr("href");
        $("#image_list a").attr("src", imageURL);
     
        var caption = $("this").attr("title");
        $("#caption").text(caption);
        evt.preventDefault();
    }); //end click```

```

https://i.imgur.com/Trkchty.png
(The HTML was automatically rendering itself)
 
Last edited by a moderator:
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top