Mouseenter&Mouseleave 点击
Mouseenter&Mouseleave to Click
我有 iframe 页面,它会在您悬停时显示。我想将其更改为单击。不知何故它不起作用。
JS:
$('section div').mouseenter(function(){
$(this).css('height', '80vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
});
$('section div').mouseleave(function(){
$(this).css('height', '2.5vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
});
CSS:
iframe {
border: 0;
width: 100%;
height: 100%;
transition: 1s;
z-index: 2000;
}
#info {
position: fixed;
top: 0;
height: 80vh;
width: 100%;
transition: 1s;
z-index: 1;
}
section {
position: fixed;
bottom: 0;
width: 100%;
z-index: 2000;
}
HTML:
<body>
<section></section>
</body>
有时我的试用成功了,但只是在 iframe 本身上(空白),因此当 iframe 充满内容时没有任何反应,也许这只是目标的问题。
我不太明白你的问题,你的 click
代码丢失了。据我所知,您可以使用以下代码实现此目的:
$('section div').click(function() {
// This part is not really needed
if (this.state === undefined) {
this.state = 0;
}
// end of not needed part
if (this.state) {
$(this).css('height', '2.5vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
this.state = 0;
} else {
$(this).css('height', '80vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
this.state = 1;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
section {
margin: 10px;
}
</style>
<div>
<section>
<div style="background-color: red; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: green; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: blue; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: black; height: 2.5vh; width: 100%"></div>
</section>
</div>
我有 iframe 页面,它会在您悬停时显示。我想将其更改为单击。不知何故它不起作用。
JS:
$('section div').mouseenter(function(){
$(this).css('height', '80vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
});
$('section div').mouseleave(function(){
$(this).css('height', '2.5vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
});
CSS:
iframe {
border: 0;
width: 100%;
height: 100%;
transition: 1s;
z-index: 2000;
}
#info {
position: fixed;
top: 0;
height: 80vh;
width: 100%;
transition: 1s;
z-index: 1;
}
section {
position: fixed;
bottom: 0;
width: 100%;
z-index: 2000;
}
HTML:
<body>
<section></section>
</body>
有时我的试用成功了,但只是在 iframe 本身上(空白),因此当 iframe 充满内容时没有任何反应,也许这只是目标的问题。
我不太明白你的问题,你的 click
代码丢失了。据我所知,您可以使用以下代码实现此目的:
$('section div').click(function() {
// This part is not really needed
if (this.state === undefined) {
this.state = 0;
}
// end of not needed part
if (this.state) {
$(this).css('height', '2.5vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
this.state = 0;
} else {
$(this).css('height', '80vh');
$(this).css('width', '100%');
$('#info').css('width', '100%');
this.state = 1;
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<style>
section {
margin: 10px;
}
</style>
<div>
<section>
<div style="background-color: red; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: green; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: blue; height: 2.5vh; width: 100%"></div>
</section>
<section>
<div style="background-color: black; height: 2.5vh; width: 100%"></div>
</section>
</div>