我不太熟悉使用jquery/css。我添加了DropIt jquery插件的文件(http://dev7studios.com/dropit/)。配置單個級別下拉菜單
我期待做懸停我的例子。我可以使用幫助來實現它,因爲我的方法是完全錯誤的。我將代碼插入到我的ruby on rails項目中。
application.html.slim:
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "https://js.stripe.com/v2/","application"
= javascript_include_tag "//www.google.com/jsapi", "chartkick"
= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js","application"
= javascript_include_tag "dropit.js","application"
= stylesheet_link_tag "dropit"
最終的結果看起來像這樣...
哪項是錯誤的。它應該是這樣的......
而當你將鼠標懸停在歡迎,用戶名,它會顯示在下拉菜單中。
具有錯誤執行的jQuery插件的當前代碼:
_header.html.slim
javascript:
$(document).ready(function() {
$('.menu').dropit();
});
#header
.wrapper
.login_sec
.col
ul.dropit
li.dropit-trigger.dropit-open
a href=""
=image_tag "login_icon1.png"
span
'Welcome,
= logged_in_user.username
ul.dropit-submenu
li
a href="#" Some Action 1
li
a href="#" Some Action 2
li
a href="#" Some Action 3
li
a href="#" Some Action 4
=image_tag "profile_link_img.png", class: 'img'
.col.col2
a href="/conversations"
=image_tag "login_icon2.png"
span Messages
/=image_tag "login_icon4.png", class: 'img4'
span class="messbg_icon" =unread_messages(current_user)
/=unread_messages(current_user)
.col.col3
a href="/logout"
=image_tag "login_icon3.png", class: 'img3'
原始代碼而不jQuery插件:
#header
.wrapper
.login_sec
.col
a href=""
=image_tag "login_icon1.png"
span
'Welcome,
= logged_in_user.username
=image_tag "profile_link_img.png", class: 'img'
.col.col2
a href="/conversations"
=image_tag "login_icon2.png"
span Messages
/=image_tag "login_icon4.png", class: 'img4'
span class="messbg_icon" =unread_messages(current_user)
/=unread_messages(current_user)
.col.col3
a href="/logout"
=image_tag "login_icon3.png", class: 'img3'
/資產/stylesheets/dropit.css:
.dropit {
list-style: none;
padding: 0;
margin: 0;
}
.dropit .dropit-trigger { position: relative; }
.dropit .dropit-submenu {
position: absolute;
top: 100%;
left: 0; /* dropdown left or right */
z-index: 1000;
display: none;
min-width: 150px;
list-style: none;
padding: 0;
margin: 0;
}
.dropit .dropit-open .dropit-submenu { display: block; }
/assets/javascripts/dropit.js:
.dropit {
list-style: none;
padding: 0;
margin: 0;
}
.dropit .dropit-trigger { position: relative; }
.dropit .dropit-submenu {
position: absolute;
top: 100%;
left: 0; /* dropdown left or right */
z-index: 1000;
display: none;
min-width: 150px;
list-style: none;
padding: 0;
margin: 0;
}
.dropit .dropit-open .dropit-submenu { display: block; }
請創建一個示例。真的很難讀取代碼.. – 2014-12-04 20:34:46
@AlexChar對不起。我一直在尋找的確切例子是在Dropit頁面http://dev7studios.com/dropit/爲他們的'哈弗我'例子。從我的屏幕截圖中可以看出,菜單自動出現,沒有懸停。 – 2014-12-04 20:36:20
我想你可以試試smartmenus。您可以構建懸停下拉菜單和常規可點擊菜單。如果你喜歡,我可以在一個簡單的代碼中回答問題。 http://www.smartmenus.org/ – BernieSF 2014-12-04 20:58:20