search

Home  >  Q&A  >  body text

css - Javascript 我想让DIV向四周扩大,但是left和top控制不好,求解

以下是代码

             function messagefadein(){
                 var oalert=document.getElementById('alert_');
                 clearInterval(msg_time);
                 oalert.style.width="40px";
                 oalert.style.height="30px";
                 var speed=40;
                 var speed2=30;

                 msg_time=setInterval(function(){
                     
                     speed+=40;
                     speed2+=30;


                     if(oalert.offsetWidth>400){
                         clearInterval(msg_time);
                     }
                     else{
                         oalert.style.left=oalert.offsetLeft+10+"px";
                         oalert.style.top=oalert.offsetTop+10+"px";
                         oalert.style.width=oalert.offsetWidth+speed+"px";
                         oalert.style.height=oalert.offsetHeight+speed2+"px"
                     }
                 },30);

                 oalert.style.display="block";

             }

这段代码运行完,总是从左上角扩大,然后往左上方移动几个PX;丝毫没有头绪,请问要怎么改写呢?万分感谢!!

大家讲道理大家讲道理2902 days ago285

reply all(3)I'll reply

  • 黄舟

    黄舟2017-04-10 17:09:38

    为什么不试试css3的放大属性...

    reply
    0
  • PHP中文网

    PHP中文网2017-04-10 17:09:38

    之所以从左上角放大,是因为这个p的位置并没有移动。之所以向左上角移动了几个像素,是因为你的offsetTop和offsetLeft等于10。

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-10 17:09:38

    这些扩大效果建议使用jQuery自带的动画效果,或者采用css提供的效果。

    reply
    0
  • Cancelreply