我想創建一些隱藏的選項,除非用戶在特定區域使用鼠標。讓我們舉個例子:Google+個人資料頁面:創建懸停可見按鈕
當你與圖片上的鼠標光標去,會出現按鈕。
這裏是我的嘗試:
var $button = $("#button");
$("#profile-picture").on("mouseover", function() {
$button.show();
}).on("mouseout", function() {
$button.hide();
});
#profile-picture {
width: 150px;
height: 100px;
}
#button {
position: absolute;
display: none;
width: 30px;
height: 30px;
top: 45px;
left: 70px;
opacity: 0.75;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<img src="http://datastore01.rediff.com/h450-w670/thumb/69586A645B6D2A2E3131/ckez1n08svw8f3en.D.0.Sidharth-Malhotra-Student-of-the-Year-Photo.jpg" id="profile-picture">
<img src="http://img3.wikia.nocookie.net/__cb20090227194712/java/images/0/0e/Camera_icon.gif" id="button" />
的問題是,當我將光標放在#button
去,它閃爍。我能做什麼?
你爲什麼做這與jQuery?您可以使用css :) – 2014-10-28 20:10:52
,因爲當您將鼠標懸停在按鈕上時,會觸發按鈕上的鼠標懸停。 – vaso123 2014-10-28 20:10:55
@BojanPetkovski,我需要在該按鈕上有'click()'事件。發佈你的想法,我不會downvote! – Victor 2014-10-28 20:11:55