js实现顶部悬停效果

//gif是横盘把头歪着看会好点 //!!!!!!!!!!

<!doctype html>
<html>

    <head>
        <meta charset="UTF-8">
        <title></title>
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <link href="{$resource}/css/mui.min.css" rel="stylesheet" />
    </head>
    <style type="text/css">
        body,.mui-content{
            background: white;
        }
        .shop-img-box{
            width: 100%;
            height: 120px;
            background-image: url({$resource}/images/shopbg.jpg);
            background-size: 100% 100%;
            position: relative;
        }
        .mui-action-back{
            margin-top: 12px;
            color: white;
            margin-left: 2%;
            margin-right: 5px;
        }
        .search-box{
            height: 38px;
            display: flex;
            border-bottom: 1px solid white;
            margin-right: 3%;
        }
        .srach-img{
            height: 20px;
            width: 20px;
            margin-top: 11px;
            margin-right: 10px;
        }
        .search-input{
            border: none;
            background: none;
            margin-top: 11px;
            font-size: 90%;
            height: 22px;
            line-height: 22px;
            width: 72%;
            color: white;
            text-align: center;
        }
        input::-webkit-input-placeholder {
            font-size: 90%;
            color: white;
        }
        .fenlei-img{
            width: 18%;
            height: 22px;
            line-height: 11px;
            border: none;
            margin-top: 11px;
            color: #999999;
            background: white;
            font-size: 75%;
        }
        .search-content{
            width: 100%;
            height: 44px;
            position: fixed;
            top: 0px;
            width: 100%;
            z-index: 999;
            background: #333;
        }
        .container-box{
            height: 100%;
            overflow-x: hidden;
            overflow-y: scroll
        }
        .bg-img{
            background-image: url({$resource}/images/shopbg.jpg);
            background-size: 100% 100%;
            width: 100%;
            height: 150px;
        }
        .group-box{
            width: 100%;
            height: 30px;
            background: red;
        }
        .product-box{
            height: auto;
            width: 100%;
        }
        .product-data{
            height: 100px;
            width: 100%;
            margin-bottom: 5px;
            background: olive;
        }            
    </style>
    <body>
        <div id="shopdata" class="mui-content">
            <div class="search-content">
                <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
                <div class="search-box">
                    <img class="srach-img mui-pull-left" src="{$resource}/images/sbai.png"/>
                    <input placeholder="搜索该店铺商品" class="search-input mui-pull-left"/>
                    <button class="fenlei-img mui-pull-right" >搜索</button>
                </div>                
            </div>
            <div id="floatBox1" class="group-box" style="position: fixed;top: 44px;z-index: 999;display: none;">
                
            </div>
            <div id="scrollBox" style="top: 44px;height: 100%;overflow: scroll;" class="mui-scroll-wrapper">
                <div  class="mui-scroll" style="height: 100%;background: #EFEFEF;">
                    <div style="background-image: url({$resource}/images/shopbg.jpg);" class="bg-img">
                    </div>
                    <div id="floatBox" class="group-box">
                    </div>
                    <div class="product-box">
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                        <div class="product-data">
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <script src="{$resource}/js/mui.min.js"></script>
        <script src="{$resource}/js/vue.min.js"></script>
        <script type="text/javascript">
            var wrapper = document.querySelector(".mui-scroll-wrapper");
            wrapper.style.height = (wrapper.offsetHeight - 44) +"px";        
            var v = new Vue({
                el:"#shopdata",
                data:{
                },
                methods:{
                },
            });
            document.getElementById('scrollBox').addEventListener('scroll', function(e) {
                var floatBox = document.getElementById("floatBox");
                var floatBox1 = document.getElementById("floatBox1");
                if(e.target.scrollTop>140){
                    floatBox.style.display = "none";
                    floatBox1.style.display = "block";
                }else{
                    floatBox.style.display = "block";
                    floatBox1.style.display = "none";
                }
            });            
        </script>
    </body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_42307129/article/details/86543403
今日推荐