2013-08-07 159 views

回答

1

從理論上講,這應該不會太難寫自己。這是在頁面某些部分懸停時實現箭頭的起點。您只需要根據用戶當前正在查看的部分來處理附加到箭頭的特定鏈接。

詳情請參見注釋。

Fiddle

注意的是,在小提琴我用event.pageXevent.pageY得到當前鼠標的位置,但在現實中,你應該使用event.screenXevent.screenY。因爲小提琴中的演示作爲一個小窗口嵌入到實際頁面中,所以使用後者將無法工作。

// Define how wide the areas should be 
// where the arrow appears 
var top_nav_height = 70; 
var bottom_nav_height = 70; 

// Get some dimensions 
var page_height = $(document).height(); 
var half_arrow_size = $('.uparrow').width()/2; 

// Listen to the user moving their mouse 
$(document).mousemove(function(event) { 
    // Where is the mouse? 
    var pos_y = event.screenY; // Distance from top of the page 
    var pos_x = event.screenX; // Distance from left of the page 
    var in_area; 
    // Leave a 5px space to hide the arrows when 
    // the pointer moves outside of the page 
    if (pos_y <= top_nav_height 
     && pos_y > 5) { 
     in_area = 'top_nav'; 
    } 
    else if (page_height - pos_y <= bottom_nav_height 
      && page_height - pos_y > 5) { 
     in_area = 'bottom_nav'; 
    } 

    // Show the arrow when in a nav area 
    switch(in_area) { 

     // We are in the top nav area 
     case 'top_nav': 
      // Show the .uparrow and have it follow the mouse 
      $('.uparrow') 
       .show() 
       .css({ 
        top: pos_y - half_arrow_size, 
        left: pos_x - half_arrow_size 
       }); 
      break; 

     // We are in the bottom nav area 
     case 'bottom_nav': 
      // Show the .bottomarrow and have it follow the mouse 
      $('.bottomarrow') 
       .show() 
       .css({ 
        top: pos_y - half_arrow_size, 
        left: pos_x - half_arrow_size 
       }); 
      break; 

     // We aren't in a nav area 
     default: 
      // Hide both arrows 
      $('.uparrow, .bottomarrow').hide(); 
    } 

    // Decide where the arrow should link 

}); 

要處理的環節,我想你也可以有單獨的一組上你的頁面的每個部分的箭頭,讓他們鏈接到目標幾乎可以被硬編碼。

+0

謝謝Elise!這是一個非常好的起點。如果你只能解釋如何使用硬編碼鏈接,或者如何獲取當前部分,然後使用該href作爲鏈接。問題在於我無法獲得當前的部分href,因爲它與skrollr.js衝突,後者是我用於本網站的插件。如果你有興趣,這裏是鏈接:http://m10.auroralighting.com/m10V2/index.html – suludi

+0

更新:有趣,你說我應該event.page改變event.screen,但它僅與頁作品,如果我使用屏幕,行爲不符合預期。 – suludi

+0

更新-2:不幸的是,它不會工作。至少它不會工作,你可以檢查上面的鏈接,箭頭只顯示在網站的頂部,就是這樣。我想這是關於使用頁面(X,Y),但如果使用屏幕,我根本沒有箭頭。 – suludi