如何让我的html页面一次性使用此功能?

时间:2015-01-14 05:11:57

标签: javascript jquery html function

$(document).ready(function() {    // show popup when you click on the link

   $('.show-popup').hover(function(event){

      event.preventDefault(); // disable normal link function so that it doesn't refresh the page

      var docHeight = $(document).height(); //grab the height of the page

      var scrollTop = $(window).scrollTop(); //grab the px value from the top of the page to where >you're scrolling
      var selectedPopup = $(this).data('showpopup'); //get the corresponding popup to show

      $('.overlay-bg').show().css({ 'height' : docHeight }); //display your popup background and set >height to the page height
      $('.popup' + selectedPopup).show().css({ 'top': scrollTop + 20 + 'px' }); //show the appropriate popup >and set the content 20px from the window top

   }   

});

2 个答案:

答案 0 :(得分:0)

试试这个..

 $('.show-popup').hover(function(event){

      event.preventDefault(); // disable normal link function so that it doesn't refresh the page

      var docHeight = $(document).height(); //grab the height of the page

      var scrollTop = $(window).scrollTop(); //grab the px value from the top of the page to where >you're scrolling
      var selectedPopup = $(this).data('showpopup'); //get the corresponding popup to show

      $('.overlay-bg').show().css({ 'height' : docHeight }); //display your popup background and set >height to the page height
      $('.popup' + selectedPopup).show().css({ 'top': scrollTop + 20 + 'px' }); //show the appropriate popup >and set the content 20px from the window top

      $('.show-popup').unbind('mouseenter mouseleave'); //unbind the event handler
   }   

答案 1 :(得分:0)

试试这个

$(document).ready(function() {    // show popup when you click on the link

   $('.show-popup').hover(function(event){

      event.preventDefault(); // disable normal link function so that it doesn't refresh the page

      var docHeight = $(document).height(); //grab the height of the page

      var scrollTop = $(window).scrollTop(); //grab the px value from the top of the page to where >you're scrolling
      var selectedPopup = $(this).data('showpopup'); //get the corresponding popup to show

      $('.overlay-bg').show().css({ 'height' : docHeight }); //display your popup background and set >height to the page height
      $('.popup' + selectedPopup).show().css({ 'top': scrollTop + 20 + 'px' }); //show the appropriate popup >and set the content 20px from the window top
      $(this).removeClass("show-popup");

   }   

});