javascript - HTML 正文不会向右滑动

标签 javascript jquery html css

我写了一些 JQuery/Javascript,想要在菜单中创建一个幻灯片,将背景图像推到一边。菜单本身滑动得很好,但由于某种原因我无法让主体移动过来。这是 JavaScript、HTML 和 CSS。

var main = function(){
$('.icon').click(function()
{
$('.menu').animate({
left: "0px"
}, 200);

$('.body').animate({
left:"300px"
}, 200);
});
};

$(document).ready(main);
@charset "utf-8";
body {
	background-image: url(http://wallpapercave.com/wp/U7rb02o.jpg);
	background-size: cover;
	left: 0px;
	position: relative;
	margin: 0px;
	overflow: hidden;
	top: 0px;
	right: 0px;
	bottom: 0px;
}
.menu {

	background-image: url((https
://image.freepik.com/free-vector/white-cubes-pattern_1053-248.jpg))
	background: url("https://image.freepik.com/free-vector/white-cubes-pattern_1053-248.jpg");
	background-repeat: repeat;
	background-position: left top;
	background-image: url(http://wallpapers.ae/wp-content/uploads/2014/10/Black-Pattern-Background-Wallpaper.jpg);
	height: 100%;
	width: 300px;
	position: fixed;
	left: -300px;
	cursor: pointer;
}
.icon {
	padding-top: 25px;
	padding-right: 0px;
	padding-left: 25px;
	padding-bottom: 25px;
	width: 75px;
	cursor: pointer;
	height: 40px;
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JQuery Test</title>
<link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="body">
<div class="icon">

</div>
</div>
<div class="menu">
</div>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="app.js"></script>
</body>
</html>

最佳答案

类似这样的事情应该可以帮助您开始:

$(document).ready(function(){
  $('.icon').click(function(){
    main();
  });
});

function main() {
  $('.menu').animate({
    left: 0
  }, 200);

  $('.body').animate({
    left: "300px"
  }, 200);
}
@charset "utf-8";
body {
	background-image: url(http://wallpapercave.com/wp/U7rb02o.jpg);
	background-size: cover;
	left: 0px;
	position: relative;
	margin: 0px;
	overflow: hidden;
	top: 0px;
	right: 0px;
	bottom: 0px;
}
.menu {

	background-image: url((https
://image.freepik.com/free-vector/white-cubes-pattern_1053-248.jpg))
	background: url("https://image.freepik.com/free-vector/white-cubes-pattern_1053-248.jpg");
	background-repeat: repeat;
	background-position: left top;
	background-image: url(http://wallpapers.ae/wp-content/uploads/2014/10/Black-Pattern-Background-Wallpaper.jpg);
	height: 100%;
	width: 300px;
	position: fixed;
	left: -300px;
	cursor: pointer;
}
.icon {
	padding-top: 25px;
	padding-right: 0px;
	padding-left: 25px;
	padding-bottom: 25px;
	width: 75px;
	cursor: pointer;
	height: 40px;
  z-index:999;
  position:absolute;
  top:30px;
  background:red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<div class="body">
  <div class="icon"></div>
</div>
<div class="menu"></div>

关于javascript - HTML 正文不会向右滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39187060/

相关文章:

javascript - jQuery jeditable错误对象[对象对象]没有方法 'editable'

javascript - 如何调用一个函数,其名称在 Json 对象中传递?

javascript - 无法让 jQuery 在图像后面滑动

jquery - 显示 Facebook、Instagram 和其他社交网站等更新

html - 将某些 html 元素复制或转换到新的子窗口

html - 图像 100% 的屏幕(滚动前)

javascript - 带闪光灯的 Html5 视频循环

javascript - array.slice 不起作用,而不是减去一些值,它只是按原样复制数组

Javascript/CSS3 转换问题

javascript - Sharepoint 导航停止使用嵌入到页面中的此脚本