老师,请教一下!卡壳了。。。
学了鼠标移入移出事件,自己心血来潮想模仿一下这个效果。。。。
但是突然想不出思路了,像复旦大学官网这个效果怎么做的。我理解是鼠标移入照片后,整体变长像左滑动,那么文字部分是隐藏起来了吗,等鼠标移入后显示出来?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>move</title>
<style>
.body{
width: 1100px;
margin: 0;
padding: 0;
}
.box{
position: relative;
width: 1100px;
height: 200px;
background-color: rgb(243, 244, 245);
margin: 0 auto;
margin-top: 30px;
}
.title{
position: absolute;
bottom: 200px;
width: 100px;
height: 30px;
line-height: 30px;
border-radius: 3px;
text-align: center;
letter-spacing: 2px;
background-color: rgb(11, 236, 86);
}
.box_content{
width: 1100px;
height: 200px;
overflow: hidden;
}
.one{
float: left;
width: 420px;
height: 200px;
background-color: rgb(245, 31, 245);
}
.one_right{
width: 200px;
height: 200px;
float: right;
background-color: #fff;
}
.two{
float: left;
width: 210px;
height: 200px;
background-color: rgb(31, 238, 245);
margin-left: 16px;
}
.thr{
float: left;
width: 210px;
height: 200px;
background-color: rgb(247, 232, 22);
margin-left: 16px;
}
.fou{
float: left;
width: 210px;
height: 200px;
background-color: rgb(14, 245, 26);
margin-left: 16px;
}
</style>
</head>
<body>
<div class="box">
<div class="title">
看我移动
</div>
<div class="box_content">
<div class="one">
<div class="one_right">你好吗</div>
</div>
<div class="two"></div>
<div class="thr"></div>
<div class="fou"></div>
<div class="fiv"></div>
</div>
</div>
</body>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js">
$(document).ready(function(){
$('.two').mouseenter(function(){
})
});
</script>
</html>
正在回答
同学你好,jQuery中的移入显示插件效果,例如:
https://www.jq22.com/yanshi4782
推拉效果
虽然实现效果和同学描述的不完全一致,但是是类似这样的插件,了解一下即可。
祝学习愉快!
同学你好,问题解答如下:
1、第三个元素闭合标签没写,所以导致第三个嵌套着第四个。添加一下就好
2、js上移入的时候先设置了显示,然后再设置隐藏,这是不对的
需要隐藏其他的文本,参考下面修改:
$(document).ready(function() {
// 第二个动画
$(".two").mouseenter(function() {
$(".two").animate({
right: "200px"
});
$(".two .two_text").show().animate({
'width': '210px'
});
$('.one_right .one_text').hide();
}).mouseleave(function() {
$('.two').animate({
'right': '0'
});
$(".two .two_text").hide().animate({
'width': '0'
});
$('.one_right .one_text').show();
});
// 第三个动画
$(".thr").mouseenter(function() {
$(".thr").animate({
right: "200px"
});
$(".two").animate({
right: "200px"
});
$(".thr .thr_text").show().animate({
'width': '210px'
});
// $('.thr_right .thr_text').hide();
$('.two_right .two_text').hide();
$('.one_right .one_text').hide();
})
.mouseleave(function() {
$('.thr').animate({
'right': '0'
});
$('.two').animate({
'right': '200px'
});
$(".thr .thr_text").hide().animate({
'width': '0'
});
$('.two_right .two_text').show().animate({
'width': '210px'
});
});
// // 第四个动画
$(".fou").mouseenter(function() {
$(".fou").animate({
right: "200px"
});
$(".thr").animate({
right: "200px"
});
$(".two").animate({
right: "200px"
});
$(".fou .fou_text").show().animate({
'width': '210px'
});
$('.thr_right .thr_text').hide();
$('.two_right .two_text').hide();
$('.one_right .one_text').hide();
})
.mouseleave(function() {
$('.fou').animate({
'right': '0'
});
$('.thr').animate({
'right': '200px'
});
$('.two').animate({
'right': '200px'
});
$(".fou .fou_text").hide().animate({
'width': '0'
});
// $('.fou_right .fou_text').show();
$('.thr_right .thr_text').show().animate({
'width': '210px'
});
});
});
不过这样修改实现的是每一个元素挨着移入移出,跳着移入的话效果会有问题。
建议暂时先不考虑这个问题,这样的效果一般会使用插件完成,自己写的话太复杂,明白逻辑即可。
祝学习愉快!
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星