English 中文(简体)
j Query - preload pornography based on solidem
原标题:jQuery - preload images based on anchor class

因此,我有以下超文本:

<ul id="nav">
    <li><a href="somepage1.php" class="class1">Link1</a></li>
    <li><a href="somepage2.php" class="class2">Link2</a></li>
</ul>

频率功能:

(function($) {
    var imgList = [];
    $.extend({
        preload: function(imgArr, option) {
            var setting = $.extend({
                init: function(loaded, total) {},
                loaded: function(img, loaded, total) {},
                loaded_all: function(loaded, total) {}
            }, option);
            var total = imgArr.length;
            var loaded = 0;

            setting.init(0, total);
            for(var i in imgArr) {
                imgList.push($("<img />")
                    .attr("src", imgArr[i])
                    .load(function() {
                        loaded++;
                        setting.loaded(this, loaded, total);
                        if(loaded == total) {
                            setting.loaded_all(loaded, total);
                        }
                    })
                );
            }

        }
    });
})(jQuery);

备妥的触发点文件(简化):

$.preload([
     path/to/image.jpg ,
     path/to/image2.jpg ,
     path/to/image3.jpg ,
     path/to/image4.jpg ,
]);

It works really well, but I need to enhance it. When user click on anchor with class class1 , preloader should read images which are assigned to specific array. And I would need to write $.preload only once.

因此,我的想法是建立两个不同的阵列,如:

var arraysClass1 = [
     path/to/image.jpg ,
     path/to/image2.jpg ,
     path/to/image3.jpg ,
     path/to/image4.jpg 
];

var arraysClass2 = [
     path/to/image5.jpg ,
     path/to/image6.jpg ,
     path/to/image7.jpg ,
     path/to/image8.jpg 
];

之后,便制作文件,如灯塔。 <Im 困在此处,代码灯有误

$( #nav a ).live("click", (function(event){
    event.preventDefault();
    var getClass =  . +$(this).attr("class");
    $(function() {
        $.preload([
            if(getClass== .class1 ){
                arrayClass1;
            }
            elseif(getClass== .class2 ){
                arrayClass2;
            }

        ]);
    });

I dont知道如何在美元封顶([...])内建立综合框架逻辑;

最佳回答

这里是你们重新寻求的法典的一部分:

$( #nav a ).live("click", function(event){
    event.preventDefault();
    usearr=  ;
    if ($(this).attr("class")=="class1") {
        usearr=arraysClass1;
    } else if ($(this).attr("class")=="class2") {
        usearr=arraysClass2;
    }
    $.preload(usearr);
});
问题回答

为什么你发现在美元外的近似物体。

$( #nav a ).live("click", (function(event){
    event.preventDefault();
    var getClass =  . +$(this).attr("class");
    var targetObj ;
     if(getClass== .class1 ){
                targetObj = arrayClass1;
     }
     else if(getClass== .class2 ){
                targetObj = arrayClass2;
     }  
        $.preload(targetObj);
});

和你本人在点击背上需要另一个<代码>$(功能)。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签