博客列表 >JQuery获取滚动值案例-2019年1月22日

JQuery获取滚动值案例-2019年1月22日

的博客
的博客原创
2019年01月25日 00:12:11689浏览

实例

<!DOCTYPE html>
<html>
<head>
  <title>获取滚动值案例</title>
  <link rel="icon" type="image/x-icon" href="images/2.png"> 
   <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
   <style type="text/css">
      *{margin: 0;padding: 0;}
      .content{ width:100%;height:60px;
                background: rgba(160,3,162,0.1);
                box-shadow: 1px 3px 7px #ccc;
                line-height: 60px;
                position: fixed;
              }
      form{width: 500px;height: 35px;position: relative;margin: 0 auto;}
      input{width:480px;height: 35px;border-radius: 20px;border:none;outline: none;padding-left:20px;}
      button{width: 70px;height:35px;order:none; 
            border-top-right-radius: 20px;border-bottom-right-radius: 20px;border: none;
            color: #fff;position: absolute;right:0;top:14px;
            outline: none;font-weight: bold;
            background: rgba(160,3,162,0.4);
          }
      [placeholder]{color:rgba(160,3,162,0.6)}
      .pic{width: 70%;height: 580px;background: url(images/3.jpg);margin: 0 auto;}
      .box{width: 70%;height:1200px;background:rgba(108,108,106,0.1);margin: 0 auto; }
   </style>
  <script>
    $(document).ready(function () {
    
     $(window).scroll(function () { 
       if($(window).scrollTop()>60){
         $(".content").hide();
       }else {
        $(".content").show().css("background","rgba(160,3,162,0.1)" );
       }
       if($(window).scrollTop()>580){
        $(".content").show().css("background","rgb(159, 3, 162)" );
       }
     });
    });
  </script>
</head>


<body> 
<!-- 顶部导航 -->
 <div class="content">
   <form>
    <input type="text" placeholder="# 请输入关键词 #">
    <button>全网搜</button>
  </form>
 </div>
 <!-- 轮播图 -->
 <div class="pic"></div>
 <!-- 页面详情 -->
 <div class="box"></div>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例


声明:本文内容转载自脚本之家,由网友自发贡献,版权归原作者所有,如您发现涉嫌抄袭侵权,请联系admin@php.cn 核实处理。
全部评论
文明上网理性发言,请遵守新闻评论服务协议