来自Backstretch(backstretch.js)的图片在一个页面中爬进到Durandal.js中的其他页面的后伸

时间:2014-10-18 09:24:42

标签: javascript jquery durandal jquery-backstretch

我已将Durandal.js用于我的SPA。我需要在某些页面中将图像幻灯片显示为背景,我正在使用jquery-backstretch。我从网络后端获取图像。在正常速度的页面之间导航时,一切正常。但是,当我从一个具有后伸的页面导航到另一个具有后伸的页面时,第一页中的后伸图像也会在第二页中出现。调试时,只有正确的图像被传递到第二页。幻灯片放映也没有在适当的时间间隔内运行。所以它必须是被调用的后伸。

请告诉我如何阻止先前的后退再次出现。以下是相关的代码段。

这是我的第一页(带有backstretch)viewmodel代码。

var id = 0;
var backstetcharray;
function loadbackstretchb() {
backstetcharray = new Array();
$.each(that.products, function (i, item)
{

    if(item.ProductBackImage != "")
    {
        backstetcharray.push("xxxxxxxxxx" + item.ProductBackImage);
    }

}
);
$.backstretch(backstetcharray, { duration: 5000, fade: 1500 });
}
var that;
define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
var location;
function callback() {
    window.location.href = "#individual/"+id;
    // this.deactivate();
};
return {
    products: ko.observableArray([]),
    activate: function () {
        currentpage = "products";
        that = this;
        return http.get('yyyyyyyyyyyyyyy').then(function (response) {
            that.products = response;
            loadbackstretchb();
        });

    },
    attached: function () {
        $(document).ready(function () {
            $('.contacticon').on({
            'mouseenter': function () {
                $(this).animate({ right: 0 }, { queue: false, duration: 400 });
            },
            'mouseleave': function () {
                $(this).animate({ right: -156 }, { queue: false, duration: 400 });
            }
        });
        });

        $(document).ready(function () {
            $(".mainmenucont").effect("slide", null, 1000);
        });
        //setTimeout($(".mainmenucont").effect("slide", null, 1000), 1000);

        $(document).on("click", ".ind1", function (e) {
           // alert("ind1");
            id = e.target.id;
           // $(".mainmenucont").effect("drop", null, 2000, callback(e.target.id));
            $('.mainmenucont').hide('slide', { direction: 'left' }, 1000, callback);
        });
    }
}
});

这是我的第二页(带有backstretch)viewmodel代码。(到我导航的地方)

var recs;
var open;
var i, count;
var backstetcharray;
function loadbackstretchc() {
backstetcharray = new Array();
$.each(recs, function (i, item) {

    if (item.BackgroundImage != "") {
        backstetcharray.push("xxxxxxxxxx" + item.BackgroundImage);
    }

}
);
$.backstretch(backstetcharray, { duration: 5000, fade: 1500 });
}
var that;
define(['plugins/http', 'durandal/app', 'knockout'], function (http, app, ko) {
var system = require('durandal/system');
var location;
function menucallback() {
    window.location.href = location;
    // this.deactivate();
};


return {
    activate: function (val) {
        currentpage = "recipes";
        open = val;
       that = this;
        var pdts;
        recs;
        var recipeJson = [];
         http.get('yyyyyyyyyyyyyy').then(function (response) {
            pdts = response;
            http.get('yyyyyyyyyyyy').then(function (response1) {
                recs = response1;
                loadbackstretchc();
                $.each(pdts, function (i, item) {
                    var json = [];
                    $.each(recs, function (j, jtem) {
                        if (item.DocumentTypeId == jtem.BelongstoProduct) {
                            json.push(jtem);
                        }
                    });

                    jsonitem = {}
                    jsonitem["product"] = item.ProductName;
                    jsonitem["link"] = "#" + item.UmbracoUrl;
                    jsonitem["target"] = item.UmbracoUrl;
                    jsonitem["recipes"] = json;
                    recipeJson.push(jsonitem);

                });

                // that.products = recipeJson;
                count = recipeJson.length;
                i = 0;
                return that.products(recipeJson);

            });
        });
    },
    attached: function(view) {
        $(document).ready(function () {
            $('.contacticon').on({
                'mouseenter': function () {
                    $(this).animate({ right: 0 }, { queue: false, duration: 400 });
                },
                'mouseleave': function () {
                    $(this).animate({ right: -156 }, { queue: false, duration: 400 });
                }

            });



        });
        $(document).ready(function () {
            $(".mainmenucont").effect("slide", null, 1000);
        });

        $(document).on("click", ".recipeclick", function (e) {
            console.log(e);
            location = "#recipe/" + e.target.id;
            $('.mainmenucont').hide('slide', { direction: 'left' }, 1000, menucallback);
        });



        $(document).on("click", ".locclick", function (e) {
            if (e.handled != true) {
                if (false == $(this).next().is(':visible')) {
                    $('#accordion ul').slideUp(300);
                }
                $(this).next().slideToggle(300);
                e.handled = true;
            }
        });
    },
    products: ko.observableArray([]),
    expand: function() {
        ++i;
        if (i == count) {
            $("#" + open).addClass("in");

        }
    }
};

});

0 个答案:

没有答案