-
jquery 的$(window).resize() 是如何触发window的resize事件的5
用的什么原生的javascript方法?
问题补充:
我的意思是用程序掉用$(window).resize(),这样就可以触发window的resize事件,而直接用javascript如何实现了?2012年8月19日 04:32
4个答案 按时间排序 按投票排序
-
http://www.51hint.com/end-of-jquery-resize-event.html
这个实现resize事件非常不错的2014年6月24日 09:53
-
$(window).resize()并没有正真的触发浏览器resize事件。 只是回调了绑定在window对象上onresize回调函数。
jquery的doc文档所言:引用This method is a shortcut for .bind('resize', handler) in the first and second variations, and .trigger('resize') in the third.
第三个作用是触发绑定在resize事件上的函数。
看看jquery的源码如何做到的。// Note that this is a bare JS function and not a jQuery handler handle = ontype && cur[ ontype ]; if ( handle && jQuery.acceptData( cur ) && handle.apply( cur, data ) === false ) { event.preventDefault(); }
其中cur是window对象 ontype为"onresize". handle为处理函数/回调函数。
handle.apply( cur, data ) 为真正的调用回调函数。
引用而直接用javascript如何实现了?
大概明白了吧。直接调用了绑定在window上的onresize回调函数。
简单的demo<!DOCTYPE HTML> <html lang="en"> <head> <meta charset="UTF-8"> <title>window resize trigger</title> <script type="text/javascript" src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> <script type="text/javascript"> window.onresize = function(){ alert(2222); } $(window).resize(); </script> </head> <body> </body> </html>
2012年8月19日 10:14
-
哦,我试了下可以这样:
<script type='text/javascript'>
window.onresize=function(){alert(234);};
if( document.createEvent) {
var event = document.createEvent ("HTMLEvents");
event.initEvent("resize", true, true);
window.dispatchEvent(event);
} else if(document.createEventObject){
window.fireEvent("onresize");
}
</script>
具体可以参考:
http://hi.baidu.com/flondon/item/6f515e098db48034a2332a68
http://northc.iteye.com/blog/12450482012年8月19日 08:16
-
等价于javascript中DOM的onresize事件处理
以下引自 w3cSchool:引用onresize 事件会在窗口或框架被调整大小时发生。支持该事件的 HTML 标签: <a>, <address>, <b>, <big>, <blockquote>, <body>, <button>, <cite>, <code>, <dd>, <dfn>, <div>, <dl>, <dt>, <em>, <fieldset>, <form>, <frame>, <h1> to <h6>, <hr>, <i>, <img>, <input>, <kbd>, <label>, <legend>, <li>, <object>, <ol>, <p>, <pre>, <samp>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <table>, <textarea>, <tt>, <ul>, <var>
引用支持该事件的 JavaScript 对象:
window
引用<body onresize="alert('You have changed the size of the window')">
</body>
2012年8月19日 07:43
相关推荐
$.jQuery( selector [, context] ), .jQuery( element ), .jQuery( elementArray ), .jQuery( jQueryObject ), .jQuery( ) $.jQuery( html [, ownerDocument] ), .jQuery( html, props ) $.jQuery( fn ) jQuery ...
JavaScript+jQuery 网页特效设计 jQuery-窗口、表单事件 1、窗口事件 ...触发窗口的 resize 事件 1、窗口事件_ scroll事件 x=0; $(document).ready(function(){ $("div").scroll(function(){ $("s
直观的window.resize事件,包括tick (例如resize )、 start和finish 。 jQuery(document).ready(function($){ $.resizeagent.wait = 750; $.resizeagent.on('tick', function(){ console.log('tick-A'); })...
$.data(ele,[key],[val])1.8- 队列控制 queue(e,[q]) dequeue([queueName]) clearQueue([queueName]) 插件机制 jQuery.fn.extend(object) jQuery.extend(object) 多库共存 jQuery.noConflict([ex]) 属性 ...
简单的反跳和限制jQuery实现 用法: debouncedFn = $.debounce(fn, timeout, [invokeAsap], [ctx]); throttledFn = $.throttle(fn, timeout, [ctx]);... $(window).resize($.throttle(doComplexСomputation, 300));
代码片段: function init() { var detectSize = function() { ww = $(window).width()... $(window).resize(detectSize); if (!$('body').css('textShadow')) { textShadowSupport = false; }
$ ( window ) . resize ( function ( ) { $element . cover ( 'set' ) ; } ) ; Cover 还需要将一些样式添加到您的样式表中: . something-container { position : relative; overflow : hidden; } . something ...
$(window).resize(function(){ $(".outer").centerChild(".inner"); }); $(window).resize(); }); 执照 做你他妈的想要公开许可第 2 版,2004 年 12 月 版权所有 (C) 2015 Andrey Viktorov 每个人都被允许复制...
jquery.equalizeheights注意: 该脚本只是的jQuery包装器。 您可能想直接使用它。 一个jQuery插件,用于均衡一组元素的高度。 允许并正确处理框大小:在其处理的元素上设置边框##用法简单的$ ( '.equal' ) . ...
iframe调整大小 一个简单的实用程序,可将iframe调整为其内容...window.parent.$(window.frameElement).trigger("sizeToContent"); iframeResize-min-height可用于为iframe设置默认高度,并在加载内容时自动将其删除。
jQuery.extendy 常见的 jQuery 任务重新打包为独立的实用程序方法。 与 jQuery 的核心库协同工作。安装在 HTML 文档的<head>中包含最新版本的和jQuery.extendy.js : < script src =" jQuery.min.js " >...
resizestop已根据获得。 模拟“ resizestop”事件 window.resizeStop在窗口对象上模拟“ resizestop”事件。 这对于执行依赖于窗口大小的操作很有用,但是以一种或另一种... 自上一次调整大小事件触发以来,此事件在一
当浏览器窗口发生该表示,会触发resize函数 // 浏览器大小发生变化时,给id为main-container的容器设置最小高度 [removed] $(function(){ $(window).resize(function(){ $(#main-container).css(min-height, $...
jQuery 事件处理方法是 jQuery 中的核心函数。 事件处理程序指的是当 HTML 中发生某些事件时所调用的方法。术语由事件“触发”(或“激发”)经常会被使用。 通常会把 jQuery 代码放到 部分的事件处理方法中: 实例 ...
iframe高度设置为子页面高度 ... iframe高度自适应于父页面 代码如下: //需要使用Jquery $(window).resize(function () { var webheight = document.body.clientHeight – X; //X是需要减去的高度量,例如顶部导航的
jQuery插件,用于基于requestAnimationFrame的事件限制 可用性 bower install jquery-throttle 安装 < script src =" bower_components/requestAnimationFrame.js/requestAnimationFrame.js " > </ script ...
jQuery侧边圣诞老人滑动面板是一款基于jQuery CSS3实现的全屏下着雪花场景动画。 var ww = 0; var wh = 0; var maxw = 0; var minw = 0; var maxh = 0; var textShadowSupport = true; ...
+ 补全 $.get,$.post 第四个参数 type 2008-08-4 18:08:47 +0800 * html()示例错误 2008-08-1 01:35:58 +0800 * 修正removeClass示例错误 2008-07-31 17:12:28 +0800 * resize/unload/select三处示例代码错误 ...
代码如下://调用函数 var pagestyle = function() { var rframe = $(“#mainFrame”); //ie7默认情况下会有上下滚动条,去掉上下15像素 var h = $(window).... //注册窗体改变大小事件 $(window).resize(pagestyle);