2015-01-14 40 views
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 

    } 

}); 
+0

單時間是指究竟是什麼?每頁一次,每週一次,曾經有一次?您需要了解本地存儲或cookie,或者更好地瞭解服務器端代碼以記住狀態並添加代碼。如果它是每頁一次,那麼你只是解除綁定事件。 – epascarello

+0

在執行完成後取消綁定事件。 –

+0

[jQuery中的['one'](http://api.jquery.com/one/)方法怎麼樣? –

回答

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 
    } 
+0

謝謝Sarath,這非常有幫助。 你能幫我嗎? https://answers.yahoo.com/question/index?qid=20150113204233AAdUMvB – Prakhar

+0

Some genious was down-voteed my answer .. :) – Sarath

+0

哪裏是http://www.minglebox.com/中的選取框 – Sarath

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"); 

    } 

}); 
+0

謝謝SimarjeetSingh。 你能回答嗎? https://answers.yahoo.com/question/index?qid=20150113204233AAdUMvB – Prakhar

相關問題