ko.bindingHandlers.hoverImage = {
init: function(element, valueAccessor) {
var options = ko.utils.unwrapObservable(valueAccessor());
$(element).bind('mouseover', function(event) {
var $this = $(this);
if (!$this.data('original-image')) {
$this.data('original-image', $this.attr('src'));
}
$this.attr('src', options);
})
.bind('mouseout', function(event) {
var $this = $(this);
$this.attr('src', $this.data('original-image'));
});
}
};
To use it,
<img src="initialImageSrc.jpg" data-bind="hoverImage: 'hoverImageSrc.jpg'>
No comments:
Post a Comment