gpt4 book ai didi

jQuery 关闭按钮效果/样式

转载 作者:行者123 更新时间:2023-12-01 06:23:55 25 4
gpt4 key购买 nike

我想要实现将鼠标悬停在 div 上一段时间后出现关闭按钮的效果。我怎么能这么做呢?顺便说一句,我对 jQuery 很陌生。

这是一个与我想要的类似的示例

enter image description here

我想在我的设计之一中出现 Angular 落里的“x”。

谢谢大家

到目前为止我做了什么:

jQuery:

$("#slider #content").on("hover", '.element', function(evt) {
var top, left;
top = $(this).offset().top;
left = $(this).offset().left;
$(".close-button").css({"top":top, "left":left});
$(".close-button").show();
});

我认为 div 和 div 的样式是无关紧要的,如果不是,我会将其发布在这里。

最佳答案

下面是执行此操作的一种方法,给出以下 HTML:

<a href="#" class="modalShow">show modal</a> <a href="#" class="modalShow">show modal</a>
<div class="modal">
<span class="close">X</span>
<p>Some text in the first modal div</p>
</div>
<div class="modal">
<span class="close">X</span>
<p>Some text in the second modal div</p>
</div>​

还有 CSS:

.modal {
display: none;
width: 50%;
padding: 0.5em;
min-height: 6em;
border: 10px solid #000;
border: 10px solid rgba(0,0,0,0.5);
position: absolute;
top: 20%;
left: 50%;
margin-left: -25%;
}
span.close {
display: none;
position: absolute;
top: -2.5em;
left: -2.5em;
width: 2em;
height: 2em;
text-align: center;
line-height: 2em;
border: 10px solid #000;
border: 10px solid rgba(0,0,0,0.5);
border-radius: 2em;
background-color: #fff;
cursor: pointer;
}​

还有 jQuery:

$('a.modalShow').click(
function() {
// finds which link was clicked, and therefore which modal to show
var i = $(this).index('.modalShow');
// fades all the modal elements out
$('.modal').fadeOut(1000);
// fades the relevant modal in
$('.modal').eq(i).fadeIn(1000);
});

$('.modal').hover(
function() {
// while hovering over the modal, it fades the close element in after a delay
$(this).find('.close').delay(1000).fadeIn(500);
},
function() {
// after leaving/mouseout of the the modal, has a delay and then fades the close out
$(this).find('.close').delay(1000).fadeOut(500);
});

$('span.close').click(
function(){
// clicking the close span causes the closest ancestor modal to fadeout
$(this).closest('.modal').fadeOut(1000);
});​

JS Fiddle demo .

引用文献:

关于jQuery 关闭按钮效果/样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10097083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com