Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modal on jquery hover function

I want to try a small trick to improve the bounce rate from my website. When the user is moving the cursor on the first 5px from the top of the page I suppose that he want to leave the page so I want to give him a modal with a search box or with some related articles.

So here we are:

$(document).ready(function(){
$( "#test" ).hover(function() {
        //alert("testing the mouseover");
        return false;
});  
});
 
#test is the id of that 5px div from the top of the page that I was talking about.

The problem is that I don't know how to replace the alert with my bootstrap modal.

<div class="modal fade bs-example-modal-sm" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      ...
    </div>
  </div>
</div>
like image 283
crixi Avatar asked Oct 20 '25 05:10

crixi


2 Answers

Try this:

 $(document).ready(function(){
    $( "#test" ).hover(function() {
           $('.modal').modal({
        show: true
    });
  });  
});

JSFiddle

like image 95
Peter Noble Avatar answered Oct 21 '25 19:10

Peter Noble


I would put an id on your modal and then do this in place of your alert

$('#modalid').modal('show');

You could also do this by class but I am not sure if any of the classes you have listed are unique to this specific modal

like image 26
Jacob Avatar answered Oct 21 '25 18:10

Jacob



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!