简体   繁体   English

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

[英]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. 我只是知道它与这里已经存在的代码有关,但是我有两个问题。

  1. 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”(或任何我命名的名称),单击按钮将不会移动它。

  2. 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.

相关问题 如何在屏幕外加载HTML页面,然后将其滑入视图? - How do i load a HTML page off screen and then slide it into view? 如何使文本从左侧滑动(隐藏到可见),然后停在中间,然后一直滑动到右侧并滑出页面并重复? - How to make text slide from the left (hidden to visible), then stop in the middle and then slide all the way to right and out of the page and repeat? 如何使要滑动的图像从左侧0,0位置向右端移动到右侧? - How do i make the image to slide move to the right from left 0,0 position to the end right side? 如何在页面加载时加载过滤列表中的所有选项? 现在,我必须点击“全部显示”才能做到这一点 - How do I load all options in a filtered list on page load? Right now, I have to click "show all" to make that happen 此幻灯片范围,当拖动到右端时,我想显示文本,例如:无限制,我该怎么做? - This slide range , when drag to end of right , i want to display text eg: unlimited, How can i do that? 如何确保图像以正确的顺序加载到画布上? - How do I make sure that images load in the right order on the canvas? 如何显示div,然后一直向右滑动,然后逐渐淡出? - How do I make a div appear, then slide all the way to the right, then fade out slowly? 如何将菜单 go 放在旁边并在其右侧显示文本? - How do I make the menu go to the side and show text to the right of it? 如何在页面加载时使用javascript / jquery滑动/打开特定菜单项? - How do I slide/open specific menu item using javascript / jquery on page load? 如何在移动设备上触摸左右这张幻灯片? - How can I make this slide left and right with touch on mobile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM