and I want to ‘unload’ or ‘remove’ this loaded function when I click on a button so that I can load this function anew instead of loading it on top of the page,
this.loadBackground = function(){
var slide = 0;
// count the number of image
var total_image = $('#supersize li').length;
//alert(total_image);
// set the opacity of all images to 0
$('#supersize li').css({opacity: 0.0});
// add the class of active to the first image and display it (set it to full opacity)
$('#supersize li:first').addClass('active').css({opacity: 1.0});
if (total_image > 1)
{
slide = parseInt(1);
}
else
{
slide = parseInt(0);
}
$.fn.supersized.options = {
startwidth: 1024,
startheight: 768,
minsize: .50,
slideshow: slide,
slideinterval: 5000
};
$('#supersize').supersized();
$('#popup-home').hide();
$('#footer-home').hide();
$('#supersize').hide().fadeIn(1500, function(){
$('#popup-home').fadeIn(1500, function(){
$('#footer-home').fadeIn(1500);
});
});
}
it uses a plugin I came across from a website, below is the entire code of this plugin (I have modified it a little at the end of the code),
/*
Supersized - Full Screen Background/Slideshow jQuery Plugin
supersized.1.0.js
February 2009
By Sam Dunn
www.buildinternet.com / www.onemightyroar.com
*/
(function($){
//Resize image on ready or resize
$.fn.supersized = function() {
var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
if (options.slideshow == 1){
setInterval("theslideshow()", options.slideinterval);
}
$().ready(function() {
$('#supersize').resizenow();
});
$(window).bind("resize", function(){
$('#supersize').resizenow();
});
};
//Adjust image size
$.fn.resizenow = function() {
var options = $.extend($.fn.supersized.defaults, $.fn.supersized.options);
return this.each(function() {
//Define image ratio & minimum dimensions
var minwidth = options.minsize*(options.startwidth);
var minheight = options.minsize*(options.startheight);
var ratio = options.startheight/options.startwidth;
//Gather browser and current image size
var imagewidth = $(this).width();
var imageheight = $(this).height();
var browserwidth = $(window).width();
var browserheight = $(window).height();
//Check for minimum dimensions
if ((browserheight < minheight) && (browserwidth < minwidth)){
$(this).height(minheight);
$(this).width(minwidth);
}
else{
//When browser is taller
if (browserheight > browserwidth){
imageheight = browserheight;
$(this).height(browserheight);
imagewidth = browserheight/ratio;
$(this).width(imagewidth);
if (browserwidth > imagewidth){
imagewidth = browserwidth;
$(this).width(browserwidth);
imageheight = browserwidth * ratio;
$(this).height(imageheight);
}
}
//When browser is wider
if (browserwidth >= browserheight){
imagewidth = browserwidth;
$(this).width(browserwidth);
imageheight = browserwidth * ratio;
$(this).height(imageheight);
if (browserheight > imageheight){
imageheight = browserheight;
$(this).height(browserheight);
imagewidth = browserheight/ratio;
$(this).width(imagewidth);
}
}
}
return false;
});
};
$.fn.supersized.defaults = {
startwidth: 640,
startheight: 480,
minsize: .5,
slideshow: 1,
slideinterval: 5000
};
})(jQuery);
//Slideshow Add-on
function theslideshow() {
var currentslide = $('#supersize .active');
if ( currentslide.length == 0 ) currentslide = $('#supersize li:last');
var nextslide = currentslide.next().length ? currentslide.next() : $('#supersize li:first');
//nextslide.addClass('active');
//currentslide.removeClass('active');
//Set the fade in effect for the next image, show class has higher z-index
currentslide.addClass('last-active');
nextslide.css({opacity: 0.0}).addClass('active').animate({opacity: 1.0}, 1500, function(){
currentslide.animate({opacity: 0.0}, 1500).removeClass('active last-active');
});
}
but it is fine when you first load the page, the problem occurs when I load the all the content through ajax.
you will see the background images are acting strange when you click on the links at the right top, for instance if you click on ‘Asia Chic’, the images when black on and off…
thanks! great thing to know about the namespace. Tried it and manage to cancel the plugin event. but the problem still persists. I think the problem is not coming from the plugin which I dont understand at all!
please have a look at the link below you may find out what the bug actually is?
however I have to comment out this line otherwise it will have errors,
//$.fn.supersized.timer;
firebugs says…
$.fn.supersized is undefined
[Break on this error] $.fn.supersized.timer;
supersized.1.0.js (line 10)
$.fn.supersized is undefined
[Break on this error] slideinterval: 5000
Well the interval is the thing that is responsible for swapping out background images (fade out one, fade in another). When the script initializes this interval is started and changes the background every 5000 milliseconds. When you call the function again another interval is initialized that also does this, so now there are two timers. Since these timers are not in sync (don’t act at the same time) you get the funky effects you saw, which becomes even worse once more timers are started. Does that make sense?