项目遇到做个地区选择的滑动二级菜单,要通过鼠标移动地区的个数,来控制对应内容的外上高度,有个方便的方法及缺点说一下

HTML:

<div class="content" style="height: 150px;overflow: hidden;text-align: center">
      <div class="item" >
        <div>
            <h3 style="color: #FFF"><a href="">重庆</a></h3>
        </div>
        <div id="a" class="product-wrap posone" style="min-width: 400px;margin-top:-30px;height: 650px;background-color: #FFF">
            <!--名片-->
            <div class="cf">
                <div class="fl wd252 pr20">
                    <h2><a href=" ">衣服3</a></h2>
                </div>

            </div>
        </div>
    </div>
    <div class="item" >
        <div>
            <h3 style="color: #FFF">重庆</h3>
        </div>
        <div id="a" class="product-wrap posone" style="max-width: 200px;margin-top:-30px;height: 650px;background-color: #FFF">
            <!--名片-->
            <div class="cf">
                <div class="fl wd252 pr20" >
                    <h2><a href=" ">衣服1</a></h2>
                </div>
            </div>
        </div>
    </div>
    <div class="item" >
        <div>
            <h3 style="color: #FFF"><a href="">重庆</a></h3>
        </div>
        <div id="a" class="product-wrap posone" style="min-width: 400px;margin-top:-30px;height: 650px;background-color: #FFF">
            <!--名片-->
            <div class="cf">
                <div class="fl wd252 pr20">
                    <h2><a href=" ">衣服2</a></h2>
                </div>

            </div>
        </div>
    </div>
    <div class="item" >
        <div>
            <h3 style="color: #FFF"><a href="">重庆33</a></h3>
        </div>
        <div  class="product-wrap posone" style="min-width: 400px;margin-top:-30px;height: 650px;background-color: #FFF">
            <!--名片-->
            <div class="cf">
                <div class="fl wd252 pr20">
                    <h2><a href=" ">衣服33</a></h2>
                </div>

            </div>
        </div>
    </div>
</div>


<!--遍历地区条数,根据焦点所在item个数改变 .product-wrap的外上高度;fast控制队列数or速度?-->
<script type="text/javascript">
    var ps=$(".content .item");
    ps.each(function(index,el){
        $(this).on("mouseenter",function(){
            /* console.log(index);  在控制台显示位数*/
            $(".product-wrap").animate({marginTop:(index+1)*26+"px"}, "fast",function(){
                self._chat_frame_min = 1;
            });
 /* 其实正常不用(index+1)*26,如果你的item有高度的话,直接index+“px”就可以了*/
}); });</script>

1.首先通过Jq获取content下的所有item子节点

2.用each遍历,其中index 即item节点的位置数(从0 开始)

3.通过this   mouseenter执行鼠标经过item所对应的函数

重点来啦!animate方法

4.

语法 

$(selector).animate(styles,speed,easing,callback)

styles

必需。规定产生动画效果的 CSS 样式和值。

speed

可选。规定动画的速度。默认是 "normal"。

可能的值:

  • 毫秒 (比如 1500)
  • "slow"
  • "normal"
  • "fast"
easing

可选。规定在不同的动画点中设置动画速度的 easing 函数。

内置的 easing 函数:

  • swing
  • linear

扩展插件中提供更多 easing 函数。

callback

可选。animate 函数执行完之后,要执行的函数。



5.marginTop 方法,支持数字字母拼接

















  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值