首页 > 解决方案 > 需要 jquery 和 css 提示 $("elemet").css();

问题描述

我正在尝试将形状向下移动 200px $("#shape").css("top","200px"); ,但它不起作用,有什么建议吗?

> <style type="text/css">
>         #shape{
>             width: 200px;
>             height: 200px;
>             background-color: red;
>             display: none;
>             position: :relative;
>             
>         }
>     
>     </style>
<div id="shape"></div>
<script type="text/javascript">
    //var start=new Date().getTime();

    function appear(){
        $("#shape").css("top","200px");
        $("#shape").css("display","block");
        start=new Date().getTime();
    }

</script>

标签: javascriptjqueryhtmlcss

解决方案


这样做

<!DOCTYPE html>
<html>
<head>
   <title>your title</title>
</head>
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"> 
</script>
<style type="text/css">
  #shape{ width: 200px; height: 200px; background-color: red; display: none; 
  position:relative;

 }

</style>
<body>
  <div id="shape"></div>
  <script type="text/javascript">
  function appear(){
    $("#shape").css("top","200px");
    $("#shape").css("display","block");
    start=new Date().getTime();
 }
appear()
</script>
</body>
</html>

推荐阅读