美文网首页
js 隐藏与展开的效果

js 隐藏与展开的效果

作者: 程序员的自我修养 | 来源:发表于2020-05-29 09:03 被阅读0次

//parent()找到低级元素

//siblings()找到同级元素

<script>

   $(function(){

       $(".g-3>div").each(function(){

           $(this).find("p").eq(0).css({width:"350px"}).css({cursor:"pointer"})

           $(this).find("p").eq(1).css({width:"390px"}).css({cursor:"pointer"})

           $(this).find("p").eq(2).css({width:"180px"}).css({cursor:"pointer"})

           $(this).find("p").eq(3).css({width:"268px"}).css({cursor:"pointer"})

        })

       $(".icon").click(function(){

           if ($(this).attr("data-id") == 1) {

               $(this).removeClass("down")

               $(this).addClass("top")

               $(this).attr("data-id" , "0")

               $(this).parent().siblings(".wrap").css({

                   height:"100%"

               })

            } else {

               $(this).removeClass("top")

               $(this).addClass("down")

               $(this).attr("data-id" , "1")

               $(this).parent().siblings(".wrap").css({

                   height:"0"

               })

            }

        })

       $(".td:even").each(function(){

           $(this).find("p").css({background : "#f0f2f1"})

           $(this).find(".text p").css({background : "#fff"})

        })

       $(".app_p").click(function(){

               if ($(this).attr("data-id") == 1) {

                   $(this).siblings("p").find("i").removeClass("down")

                   $(this).siblings("p").find("i").addClass("top")

                   $(this).attr("data-id" , "0")

                   $(this).siblings(".wrap").css({

                       height:"100%"

                   })

                } else {

                   $(this).attr("data-id","1")

                   $(this).siblings("p").find("i").removeClass("top")

                   $(this).siblings("p").find("i").addClass("down")

                   $(this).siblings(".wrap").css({

                       height:"0"

                   })

                }

        }

        )

    })

</script>

相关文章

网友评论

      本文标题:js 隐藏与展开的效果

      本文链接:https://www.haomeiwen.com/subject/wzquohtx.html