[英]How do I make text slide to the right upon page load?
I'm not fluent in javascript and I'm trying to edit this example at w3schools to make a simple headline within a div slide to the right smoothly (from out of view) upon page load. 我不太精通javascript,并且尝试在w3schools上编辑此示例,以使div幻灯片在加载页面时顺利地(从视图外)向右滑动一个简单的标题。 I just KNOW it has something to do with the code that is already here, but I'm having two problems.
我只是知道它与这里已经存在的代码有关,但是我有两个问题。
When I turn the box they are moving into a text headline and change the "div" selector into '.headline' (or whatever I've named it), clicking the button won't move it. 当我打开框时,它们将移动到文本标题中,并将“ div”选择器更改为“ .headline”(或任何我命名的名称),单击按钮将不会移动它。
If I figure that out, I still don't know how to make it work without the button. 如果我知道了这一点,我仍然不知道如何在没有按钮的情况下使它工作。
Right now that code is invoked with a click handler, just remove the wrapper for that and execute it on page load: 现在,该代码是通过点击处理程序调用的,只需删除该包装器并在页面加载时执行即可:
$(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'
});
});
Demo: http://jsfiddle.net/tymeJV/ZWtQw/1/ 演示: http : //jsfiddle.net/tymeJV/ZWtQw/1/
if you want to make it when body loads just try these 100% working 如果您想在承受身体负荷时做到这一点,请尝试这些100%起作用
The html content and coding are as follows: 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.