繁体   English   中英

如何在页面加载时使文本向右滑动?

[英]How do I make text slide to the right upon page load?

我不太精通javascript,并且尝试在w3schools上编辑此示例,以使div幻灯片在加载页面时顺利地(从视图外)向右滑动一个简单的标题。 我只是知道它与这里已经存在的代码有关,但是我有两个问题。

  1. 当我打开框时,它们将移动到文本标题中,并将“ div”选择器更改为“ .headline”(或任何我命名的名称),单击按钮将不会移动它。

  2. 如果我知道了这一点,我仍然不知道如何在没有按钮的情况下使它工作。

现在,该代码是通过点击处理程序调用的,只需删除该包装器并在页面加载时执行即可:

$(document).ready(function() {
    $(".header").animate({ //be sure to change the class of your element to "header"
        left:'250px',
        opacity:'0.5',
        height:'150px',
        width:'150px'
    });
});

演示: http//jsfiddle.net/tymeJV/ZWtQw/1/

如果您想在承受身体负荷时做到这一点,请尝试这些100%起作用
html的内容和编码如下:

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>

var function1 = function(){ 
$(document).ready(function(){
    $("div").animate({

      left:'250px',
      opacity:'0.5',
      height:'150px',
      width:'150px'
    });
});

};
</script> 
</head>

<body onload="function1();">

<p> in the body tag  i have added onload event which tells that when body is fully loaded then do this function which has a name of function1 or you can name something else but remember <b>in script tag the name after var should be same as the name in onload event   </b></p>
<div style="background:#98bf21;height:100px;width:100px;position:absolute;">
</div>

</body>
</html>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM