菜单幻灯片,链接到页面部分平滑



当我单击标签时,我试图隐藏我的div菜单,同时顺利向下滚动到页面的一部分。该网站可以滑到我想要的位置,但我无法隐藏菜单。我使用的是CSS3和Jquery,我对Jquery仍然很陌生,但也许我只能用Jquery来做到这一点?如果我可以通过仅使用链接或标签以外的其他东西来做到这一点,那不是问题。我愿意接受建议。感谢您的帮助。

.CSS:

<style>
*{
    box-sizing:border-box;
}
body{
    padding: 0;
    margin: 0;
}
#container{
    width: 80%;
    height: 3000px;
    background-color: #A77676;
    margin: 0 auto;
    position: relative;
}
.menu-cont{
    width: 100%;
    height: 500px;
    background-color: #7B87FF;
}
.menu{
    width: 200px;
    height:400px;
    background-color: #C6C6C6;
    overflow: hidden;
    position: relative;
    top: 0;
    left: 0px;
    z-index: 10;
}
.menu-slide{
    width: 200px;
    height: 200px;
    background-color: #8BE2FF;
    position: absolute;
    top: 200px;
    right: 0;
    z-index: 11;
}
.jqueryscrollto{
    width: 100%;
    height: 200px;
    background-color: #00FF00;
    position: relative;
    margin-top: 1500px;
}
/************************************/
label.button{
    width: 25px;
    height: 25px;
    font-weight: bold;
    color: #FF0000;
    /*background-color: #1800FF;*/
    display: inline-block;
}
label.linkbutton{
    width: 25px;
    height: 25px;
    background-color: #36FF00;
    display: inline-block;
}
/********slide starter****/
input.toggle ~ .menu-slide{
    overflow: hidden;
    transition: .5s ease-in-out;
    transform: translateX(0px);
}
input.toggle:checked ~ .menu-slide{
    transform: translateX(-200px);
}
input.toggle{
    display: none;
}
/*****************************/
input.togglelink ~ .menu-slide{
    overflow: hidden;
    transition: .5s ease-in-out;
    transform: translateX(0px);
}
input.togglelink:checked ~ .menu-slide{
    transform: translateX(-200px);
}
input.togglelink{
    display: none;
}
</style>

.HTML:

<body>
<div id="container">
  <div class="menu-cont">
    <div class="menu">
        <input type="checkbox" class="toggle" id="iconbtn">
        <label class="button" for="iconbtn">ICON BUTTON</label>
        <input type="checkbox" class="togglelink" id="linkbtn" data-href="#SCROLL">
      <div class="menu-slide">
        <div class="menu-content">
          <h2>SLIDER</h2>
          <label class="linkbutton" for="linkbtn">ABOUT US-LINKBTN</label>
        </div>
      </div><!--menu slide -->
    </div><!-- menu -->
  </div><!-- menu-cont -->
  <div class="jqueryscrollto">I WANT TO SCROLL HERE</div><label id="SCROLL"></label>
</div><!-- #container -->
</body>

Jquery:

<head>
<script src="https://code.jquery.com/jquery-1.6.4.js"></script>
</head>
<body>
<script>
try {$('input').click(function(){
 href=$(this).data('href');
$('html, body').animate({
scrollTop: $(href).offset().top
}, 500);
return false;
});
} catch (error) { throw error; }
</script>
</body

我把jquery放在HTML正文的底部。

这是一种使用 Js 隐藏 html 元素的方法

 $("button").click(function(){
        $("p").hide(1000);
    });

我想通了。只是坚持看书,学习基础知识:)

$(function() {
$(document.onload)
  var left = true;
  $(".button, .icon").click(function() {
     $(".slide-container").animate({
        left: left ? "0px" : "-200px"
     }, 1000);
     left = !left;
  });
  $('.button').on('click', function(){
    href=$(this).data('href');
    $('html, body').animate({
    scrollTop: $(href).offset().top
    }, 1000);
  });
});

最新更新