简体   繁体   English

如何在加载页面时自动获取动画

[英]how to get animation automatically on loading the page

i want to make images effect automatically when the page loads. 我想在页面加载时自动使图像效果。 Right now i am using this code js 现在我正在使用此代码js

$(window).ready(function(){
$(pin).click(function(){
  $("#pin01").show().animate({left: '650px'});
})
});

and html 和html

<p id="pin">Click me</p>
<img src="mission.gif" id="pin01" style=" display:none;position:absolute;top:300px;left:300px" />

When i click the button animation occurs. 当我单击按钮时,会发生动画。 How can i make it possible to do animation automatically after page load without any button? 如何使页面加载后没有任何按钮即可自动制作动画?

Simply put the animate line within the ready or load handler depending on your exact needs 只需根据您的确切需求将动画行放入就绪或加载处理程序中

$(document).ready(function(){
    $("#pin01").show().animate({left: '650px'});
});

or 要么

$(widnow).load(function(){
    $("#pin01").show().animate({left: '650px'});
});

The document.ready event occurs when the HTML document is loaded and DOM is ready. 加载HTML文档并且DOM准备就绪时,将发生document.ready事件。 The window onload event occurs when the DOM is ready as well as all frames, images, etc have been loaded. DOM准备就绪并且所有帧,图像等都已加载时,发生window onload事件。

You can try trigger as well: 您也可以尝试触发:

$(window).ready(function(){
  $('#pin').click(function(){ //<-- note the correction, it was `$(pin)` before
    $("#pin01").show().animate({left: '650px'});
  }).trigger('click'); //<-- triggers event
});

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

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