求帮忙调整一下javascript代码,点击上下箭头切换的效果

JavaScript022

求帮忙调整一下javascript代码,点击上下箭头切换的效果,第1张

既然用了toggle,就试一下都用toggle吧,如下:

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8" />

<title>Document</title>

<style>

body {

margin:0

padding:0

}

.menu {

position: fixed

bottom: 0

left: 0

height: auto

text-align:center

width: 100%

cursor: pointer

}

.title {

width: 100%

height:40px

background: orange

text-align: center

}

.dropdown {

width: 100%

height: auto

background:red

max-height: 150px

overflow: hidden

transition: all .5s

}

.down {

max-height: 0

}

ul {

padding:0

margin:0

list-style:none

}

.triangle-top {

display: inline-block

margin: 10px

border-top: 2px solid border-right: 2px solid

width: 10px height: 10px

transform: rotate(-45deg)

}

.triangle-bottom {

display: inline-block

margin: 10px

border-bottom: 2px solid border-right: 2px solid

width: 10px height: 10px

transform: rotate(45deg)

}

</style>

</head>

<body>

<div class="menu">

<div class="dropdown down">

<ul><li>aaa</li><li>bbb</li><li>ccc</li><ul>

</div>

<div class="title" onclick="f()">

<span class="triangle triangle-top"></span>

</div>

</div>

<script>

function f() {

document.getElementsByClassName('triangle')[0].classList.toggle('triangle-top')

document.getElementsByClassName('triangle')[0].classList.toggle('triangle-bottom')

document.getElementsByClassName('dropdown')[0].classList.toggle('down')

}

</script>

</body>

</html>

望采纳,谢谢

有几种实现方式,首先jQuary是最简单的

$(document).ready(function(){

    $(选择器).onclick(function(){

        $(目标div).html("写入内容")

        //可以用请求加载内容

        $(目标div).load("请求url",function(){

            //写入回调函数

        })

    })

}

但是如果只是切换图片的话,其实不用这么麻烦,全部hide,然后一个一个show就好了……静态的话。

时间不够了…要其他方法就再追问吧……

希望有帮到你喵……