Hi
i am using expander.js a jquery plugin for expanding text.
Now here is the thing,
whenever the expand and collapse are triggered i am supposed to swap an image.
now usually that is not a problem.
One more piece of information is that there is a list of items which comes with expandable description and image hence the id inside the code.
EDIT: Will now display the full code.
The code is below:
$(document).ready(function() {
// override some default options
$('div.expandable div').expander({
slicePoint: 200, // default is 100
expandText: 'Expand', // default is 'read more...'
expandEffect: 'fadeIn',
collapseTimer: 0, // re-collapses after 5 seconds; default is 0, so no re-collapsing
userCollapseText: 'Collapse' , // default is '[collapse expanded text]'
afterExpand: function($thisElement) {
var vendorParaID = $thisElement.attr('id');
var underscore = vendorParaID.indexOf('_');
var vendorID = vendorParaID.substring(0, underscore);
$("#vendor_img_"+vendorID).attr({height : "308",
src : "img/m/"+vendorID+".jpg"
});
},
onCollapse: function($thisElement, byUser) {
//alert($thisElement.attr('id'));
var vendorParaID = $thisElement.attr('id');
var underscore = vendorParaID.indexOf('_');
var vendorID = vendorParaID.substring(0, underscore);
$("#vendor_img_"+vendorID).attr({height : "80",
src : "img/m/"+vendorID+"-crop.jpg"
});
}
});
});
However there is a lag between the change in the image.
I like to preload the image but then i am not sure how to swap it correctly.
I looked up these 2 links but i am still not sure how to make it work.
http://jquery-howto.blogspot.com/2009/02/preload-images-with-jquery.html http://jquery-howto.blogspot.com/2009/04/jquery-image-swap-or-how-to-replace.html
Please advise.