Rebinding hoverIntent jQuery plug-in
I am using a combination of Drupal Views, ajax and the hoverIntent plug-in to display content. Problem is, after an ajax request the 'hoverIntent' event is no longer bound to the my selector (in this case each row of the view). Does anyone have a solution to this?
Link to plug-in uncompressed hoverIntent js
hoverIntent home page
My code below--
hoverIntent: This expands a row if you're cursor is over it and at the same time collapses all other rows.
$('.view-latest-new .views-field-field-story-lead-image-fid').addClass('expand');
var config = {
over: function() {
var expand = $(this).find(".expand");
if(expand.css("display") == "none")
{
$(".expand").slideUp("fast");
$(this).find(".expand").slideDown("fast");
}
},
out: function() {
}
};
$('.view-home .views-row').hoverIntent(config);
EDIT: 开发者_JAVA百科Ajax:
var container = $('#content-inner');
$('#block-menu-secondary-links a').bind('click', function(){
var trigger = $(this);
var arg = trigger.attr('title');
doAjax(arg,container);
return false;
});
function doAjax(arg,container){
$.ajax({
url: 'views/ajax?view_name=home&view_display_id=page_1&view_args'+arg,
timeout:5000,
success: function(data){
var result = Drupal.parseJson(data);
updateContainer(result.display);
},
});
};
function updateContainer(content){
container.html(content);
$('.view-latest-new .views-field-field-story-lead-image-fid').addClass('expand');
$('.view-latest-new .views-row').hoverIntent(config);
}
Thanks!
EDIT 2: I've found a solution; by adding $('.view-home .views-row').hoverIntent(config);
into the updateContainer function. I'm not sure if this is the best way to go about it though. But it works.
Solution:
I have moved the 'hoverIntent' event into it's own function. Which then I have called when the document is ready and also after the ajax request has completed.
function hoverInit() {
$('.view-latest-new .views-field-field-story-lead-image-fid').addClass('expand').parent().hoverIntent(config);
}
hoverInit();
function updateContainer(content){
container.html(content);
hoverInit();
}
精彩评论